我在使用EWS将电子邮件附加到新电子邮件时遇到问题。
所以我的findResults中有Microsoft.Exchnage.Webservice.Data.Item。
如果我在电子邮件的表单数据中发现问题,那么我想将该项目附加到新电子邮件中并将其发送给主管进行手动输入。
我试过了;
EmailMessage newMessage = new EmailMessage(exchange);
newMessage.Subject = "Failed lead creation";
ItemAttachment attachment = new ItemAttachment("New Lead", message);
我似乎无法创建ItemAttachment,因为我得到的错误是#34; ItemAttachment不包含带有2个参数的构造函数"。
如何在EWS中创建新邮件,将当前项目附加到其中并发送给其他收件人?
Thaks
答案 0 :(得分:1)
你不能直接使用原始消息的MimeContent然后创建一个ItemAttachment,例如
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();
干杯 格伦
答案 1 :(得分:0)
利用Glen Scales的答案,如果您有消息ID,代码应如下所示。 有关PR_Flags扩展属性的其他信息,可以在以下链接中找到: 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;