Hi,
We are attempting to send a reply mail with embedded images using Exchange but are running into 2 separate issues.
1. When saving the generated reply message to disk the embedded image shows perfectly as expected but when actually sending (normal send, not a reply) the image is lost or sometimes added as an attachment ATT000001.png.
2. When a reply message is generated and sent as a reply (IEwsClient.Reply) the reply works without issues, however when saving this message to disk, reloading it from disk and then attempting to use it as a reply results in the following error:
A first chance exception of type 'System.Web.Services.Protocols.SoapException' occurred in System.Web.Services.dll
Additional information: The request failed schema validation: The element 'ReplyToItem' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types' has invalid child element 'ExtendedProperty' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'. List of possible elements expected: 'Subject, Body, ToRecipients, CcRecipients, BccRecipients, IsReadReceiptRequested, IsDeliveryReceiptRequested, From, ReferenceItemId, NewBodyContent' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'.
Below is some sample code we are testing with:
public void TestMailReFw()
{
using (IEWSClient client = GetEWSClient())
{
try
{
// Set conditions
ExchangeQueryBuilder builder = new ExchangeQueryBuilder();
builder.HasNoFlags(ExchangeMessageFlag.IsRead);
// Build the query
MailQuery query = builder.GetQuery();
ExchangeMessageInfoCollection messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri, query);
if (messageInfoCol.Count == 1)
Console.WriteLine("1 message in Inbox");
else
Console.WriteLine("Error! No message in Inbox");
//Generate the reply message with image
MailMessage msgReply = new MailMessage();
msgReply.HtmlBody = "<b>Html body with an image.</b> Here is an embedded image.<img src=cid:CompanyLogo>";
LinkedResource logo = new LinkedResource("CompanyLogo.png", MediaTypeNames.Image.Png);
logo.ContentId = "CompanyLogo";
msgReply.LinkedResources.Add(logo);
msgReply.IsBodyHtml = true;
//Set From, To, ReplyToList
msgReply.From = new MailAddress("address@company.com");
MailAddressCollection coll = new MailAddressCollection();
coll.Add(new MailAddress("address@company.com"));
msgReply.To.Add(new MailAddress("addressReply@company.com"));
msgReply.ReplyToList = coll;
//when checking the saved message the embedded image is visible as expected
msgReply.Save(@"c:\myreplymail.msg", Aspose.Email.Mail.SaveOptions.DefaultMsgUnicode);
MailMessage msgReplyLoaded = MailMessage.Load(@"c:\myreplymail.msg", MailMessageLoadOptions.DefaultMsg);
//When sending the reply message as new message the embedded png is lost
//client.Send(msgReply);
//When sending the reloaded reply message as a reply an error occurs
//client.Reply(msgReplyLoaded, messageInfoCol[0]);
//When sending the reply message as a reply the embedded image is lost
client.Reply(msgReply, messageInfoCol[0]);
//Setting original message as unread again
client.SetReadFlag(messageInfoCol[0].UniqueUri, false);
}
catch (Exception ex)
{
Console.WriteLine("Error in program");
}
}
}
public IEWSClient GetEWSClient()
{
const string mailboxUri = "https://outlook.office365.com/EWS/Exchange.asmx";
const string domain = "";
const string username = @"address@company.com";
const string password = @"******";
NetworkCredential credential = new NetworkCredential(username, password, domain);
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credential);
return client;
}
Am I missing something?
Best Regards,
Jurgen