Reputation: 3
Hi I have a requirement to use EWS Microsoft Exchange WebService API to redirect emails.
basically, the program read an email box on Exchange server, change to new ToAddress, CC/BCC Addresses and resend it with original subject, email body, and all attachments. it sounds like an easy job, but I could not find the easy way to do this.
I searched the EWS API, it looks like the emailMessage.Forward() or emailMessage.CreateForward() is a nice option. but when I tried them, they actually adding the Forward information (i.e. original sender, timestamp etc) in the new email body, this is not desired.
Anyone knows an easy way to do that?
or I have to do the hard way? create a new emailMessage object and copy everything from the original email object and send the new email?
Any sample code for this task is appreciated!
thanks Frank
Upvotes: 0
Views: 792
Reputation: 22032
What your trying to do won't work in EWS (or any Exchange client API) because Exchange won't let you resend the message from an Email Address your mailbox is not associated with. Eg if I send you an Email and you just change the ToAddress and try to resend it via a client API you will get an error because you don't have rights to send as Me (what your essentially doing is spoofing at that point).
If you want to redirect or copy messages to other recipients then creating a Transport Rule https://technet.microsoft.com/en-us/library/aa998315(v=exchg.160).aspx is a better option (this just adds another recipient to an existing message). Another way to do this would be if you got the MIMEContent of the message using EWS and then set the X-Sender and X-Recipient headers and then use the Replay directories https://technet.microsoft.com/en-us/library/bb124230(v=exchg.150).aspx on the Hub Server to send the message. That essentially allows you to add another BCC to a message and delivery it to another mailbox with the existing headers intact.
Upvotes: 0