Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
WebDAV .NET for Exchange
>
Tutorial
> Forward message
The following example shows you how to forward existing mail message.
C# example
using System; using System.Net; using Independentsoft.Webdav.Exchange; using Independentsoft.Webdav.Exchange.ContentClass; using Independentsoft.Webdav.Exchange.Properties; namespace Sample { class Program { static void Main(string[] args) { NetworkCredential credential = new NetworkCredential("username", "password"); WebdavSession session = new WebdavSession(credential); session.UserMailbox = "https://myserver/exchange/emailaddress"; Resource resource = new Resource(session); Mailbox myMailbox = resource.Mailbox; string messageUrl = "https://myserver/exchange/emailaddress/Inbox/message1.eml"; string forwardMessageFileName = Guid.NewGuid().ToString() + ".eml"; string forwardMessageUrl = myMailbox.Drafts + "/" + forwardMessageFileName; resource.Copy(messageUrl, forwardMessageUrl); //Remove old From/Sender/To/Cc properties PropertyName[] propertiesToRemove = new PropertyName[13]; propertiesToRemove[0] = MessageProperty.To; propertiesToRemove[1] = MessageProperty.Cc; propertiesToRemove[2] = MessageProperty.From; propertiesToRemove[3] = MessageProperty.FromName; propertiesToRemove[4] = MapiProperty.PR_SENDER_EMAIL_ADDRESS; propertiesToRemove[5] = MapiProperty.PR_SENDER_NAME; propertiesToRemove[6] = MapiProperty.PR_SENT_REPRESENTING_EMAIL_ADDRESS; propertiesToRemove[7] = MapiProperty.PR_SENT_REPRESENTING_NAME; propertiesToRemove[8] = MapiProperty.PR_RCVD_REPRESENTING_ADDRTYPE; propertiesToRemove[9] = MapiProperty.PR_RCVD_REPRESENTING_EMAIL_ADDRESS; propertiesToRemove[10] = MapiProperty.PR_RCVD_REPRESENTING_ENTRYID; propertiesToRemove[11] = MapiProperty.PR_RCVD_REPRESENTING_NAME; propertiesToRemove[12] = MapiProperty.PR_RCVD_REPRESENTING_SEARCH_KEY; resource.RemoveProperty(forwardMessageUrl, propertiesToRemove); //Set "To" property Property to = new Property(MessageProperty.To.Name, MessageProperty.To.Namespace, "user@domain.com"); resource.SetProperty(forwardMessageUrl, to); //Send message resource.Move(forwardMessageUrl, myMailbox.MailSubmission); } } }
VB example
Imports System Imports System.Net Imports Independentsoft.Webdav.Exchange Imports Independentsoft.Webdav.Exchange.ContentClass Imports Independentsoft.Webdav.Exchange.Properties Module Module1 Sub Main(ByVal args() As String) Dim credential As NetworkCredential = New NetworkCredential("username", "password") Dim session As WebdavSession = New WebdavSession(credential) session.UserMailbox = "https://myserver/exchange/emailaddress" Dim resource As Resource = New Resource(session) Dim myMailbox As Mailbox = resource.Mailbox Dim messageUrl As String = "https://myserver/exchange/emailaddress/Inbox/message1.eml" Dim forwardMessageFileName As String = Guid.NewGuid().ToString() & ".eml" Dim forwardMessageUrl As String = myMailbox.Drafts + "/" + forwardMessageFileName resource.Copy(messageUrl, forwardMessageUrl) 'Remove old From/Sender/To/Cc properties Dim propertiesToRemove() As PropertyName = New PropertyName(12) {} propertiesToRemove(0) = MessageProperty.To propertiesToRemove(1) = MessageProperty.Cc propertiesToRemove(2) = MessageProperty.From propertiesToRemove(3) = MessageProperty.FromName propertiesToRemove(4) = MapiProperty.PR_SENDER_EMAIL_ADDRESS propertiesToRemove(5) = MapiProperty.PR_SENDER_NAME propertiesToRemove(6) = MapiProperty.PR_SENT_REPRESENTING_EMAIL_ADDRESS propertiesToRemove(7) = MapiProperty.PR_SENT_REPRESENTING_NAME propertiesToRemove(8) = MapiProperty.PR_RCVD_REPRESENTING_ADDRTYPE propertiesToRemove(9) = MapiProperty.PR_RCVD_REPRESENTING_EMAIL_ADDRESS propertiesToRemove(10) = MapiProperty.PR_RCVD_REPRESENTING_ENTRYID propertiesToRemove(11) = MapiProperty.PR_RCVD_REPRESENTING_NAME propertiesToRemove(12) = MapiProperty.PR_RCVD_REPRESENTING_SEARCH_KEY resource.RemoveProperty(forwardMessageUrl, propertiesToRemove) 'Set "To" property Dim toEmail As Independentsoft.Webdav.Exchange.Property = New Independentsoft.Webdav.Exchange.Property(MessageProperty.To.Name, MessageProperty.To.Namespace, "user@domain.com") resource.SetProperty(forwardMessageUrl, toEmail) 'Send message resource.Move(forwardMessageUrl, myMailbox.MailSubmission) End Sub End Module