1

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

griegs
  • 22,624
  • 33
  • 128
  • 205

2 Answers2

2

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

Glen Scales
  • 20,495
  • 1
  • 20
  • 23
0

Utilizing answer from Glen Scales, if you have message id, code should look like below. Additional info on PR_Flags extended property can be found on folowing link: http://systemmanager.ru/windowsmobile_6_5.en/html/45cd0e95-9622-4180-bf85-290c421524f3.htm

PropertySet psPropset = new PropertySet(BasePropertySet.IdOnly);
                psPropset.Add(ItemSchema.MimeContent);
                psPropset.Add(ItemSchema.Subject);
                EmailMessage attachment = EmailMessage.Bind(_exchangeService, new ItemId(ewsItemAsAttachment).UniqueId, psPropset).Result;

                ItemAttachment Attachment = message.Attachments.AddItemAttachment<EmailMessage>();
                Attachment.Item.MimeContent = attachment.MimeContent;
                ExtendedPropertyDefinition PR_Flags = new ExtendedPropertyDefinition(3591, MapiPropertyType.Integer);
                Attachment.Item.SetExtendedProperty(PR_Flags, "1");
                Attachment.Name = attachment.Subject;
Nevres Jahic
  • 1
  • 1
  • 2