Create an email using EWS Exchange and attach another email

北慕城南 提交于 2019-12-01 13:21:44

问题


I'm having trouble attaching an email to a new email using EWS.

So i have the Microsoft.Exchnage.Webservice.Data.Item in my findResults.

If I find an issue in the form data of the email then I want to attach that item to a new email and send it to a supervisor for manual input.

I have tried;

EmailMessage newMessage = new EmailMessage(exchange);
newMessage.Subject = "Failed lead creation";
ItemAttachment attachment = new ItemAttachment("New Lead", message);

I can't seem to create the ItemAttachment as the erro I am getting is "ItemAttachment does not contain a constructor that takes 2 arguments".

How do I create a new message in EWS, attach the current Item to it and send to another recipient?

Thaks


回答1:


You can't another message directly you need to use the MimeContent of the Original Message and then create an ItemAttachment based on that eg something like

    FolderId  folderid= new FolderId(WellKnownFolderName.Inbox,"MailboxName");    
    Folder Inbox = Folder.Bind(service,folderid);  
    ItemView ivItemView =  new ItemView(1) ;     
    FindItemsResults<Item> fiItems = service.FindItems(Inbox.Id,ivItemView);
    if(fiItems.Items.Count == 1){  
    EmailMessage mail = new EmailMessage(service);   
    EmailMessage OriginalEmail = (EmailMessage)fiItems.Items[0];
    PropertySet  psPropset= new PropertySet(BasePropertySet.IdOnly);    
    psPropset.Add(ItemSchema.MimeContent);
    psPropset.Add(ItemSchema.Subject);
    OriginalEmail.Load(psPropset);  
    ItemAttachment Attachment = mail.Attachments.AddItemAttachment<EmailMessage>();
    Attachment.Item.MimeContent = OriginalEmail.MimeContent;  
    ExtendedPropertyDefinition PR_Flags = new ExtendedPropertyDefinition(3591, MapiPropertyType.Integer);    
    Attachment.Item.SetExtendedProperty(PR_Flags,"1");    
    Attachment.Name = OriginalEmail.Subject;  
    mail.Subject = "See the Attached Email";  
    mail.ToRecipients.Add("glen.scales@domain.com");
    mail.SendAndSaveCopy();     

Cheers Glen



来源:https://stackoverflow.com/questions/36192626/create-an-email-using-ews-exchange-and-attach-another-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!