In my program, I am reading an Exchange mailbox using EWS .NET API and forwarding the emails as attachment to an external email address. Code that I have used is below
private void ForwardMessage(ExchangeService exchangeService, EmailMessage item)
{
ResponseMessage responseMessage = item.CreateForward();
item.Load(new PropertySet(BasePropertySet.FirstClassProperties, new
PropertySet(){ItemSchema.MimeContent,
ItemSchema.Subject}));
var mail = new EmailMessage(exchangeService);
var attachment = mail.Attachments.AddFileAttachment(String.Format("
{0}.eml", item.Subject),
item.MimeContent.Content);
String forwardEmailAddresses =
MailProcessorSettings.Default.ForwardEmailAddress;
char[] delimiters = { ',', ';' };
foreach (var emailAddress in forwardEmailAddresses.Split(delimiters,
StringSplitOptions.RemoveEmptyEntries))
{
mail.ToRecipients.Add(emailAddress);
}
mail.Subject = item.Subject;
mail.Send();
}
I am able to open the email forwarded as attachment in Outlook. However, if I send it to Gmail or to other users using different email clients it shows up as a blank attachment.
How do I ensure that the email forwarded as an attachment preserves the original content?