自EWS几天以来一直面临着一个问题。所以我的情景是;
我是以编程方式同步GMAIL和EXCHANGE ONLINE。所以这就是我所做的;
现在问题出在这里,如何在Inbox中创建一个看起来像来自发件人的收到邮件的电子邮件;
以下是我所做的代码;
_service = new ExchangeService(ExchangeVersion.Exchange2013);
_service.TraceEnabled = true;
_service.Credentials = new WebCredentials("admin@xyz.onmicrosoft.com", "password");
_service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
_service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "xyz@xyz.onmicrosoft.com");
EmailMessage message = new EmailMessage(_service);
Random r = new Random();
message.Subject = "Email Message";
message.From = new EmailAddress("xyz@gmail.com");
message.Sender = new EmailAddress("xyz@gmail.com");
message.Body = new MessageBody(BodyType.HTML, "<HTML><body><h1>This is a voice mail.</h1></BODY></HTML>");
message.ToRecipients.Add(new EmailAddress(""));
message.Save(WellKnownFolderName.Inbox);
这样它就会在收件箱中创建一个电子邮件,但它会显示为草稿邮件。我不想要它,我希望它看起来像 RECEIVED 邮件。
我做错了吗?
答案 0 :(得分:1)
您需要在保存邮件之前设置一些属性。
// Set a delivery time
ExtendedPropertyDefinition PidTagMessageDeliveryTime =
new ExtendedPropertyDefinition(0x0E06, MapiPropertyType.SystemTime);
DateTime deliveryTime = DateTime.Now; // Or whatever deliver time you want
message.SetExtendedProperty(PidTagMessageDeliveryTime, deliveryTime);
// Indicate that this email is not a draft. Otherwise, the email will appear as a
// draft to clients.
ExtendedPropertyDefinition PR_MESSAGE_FLAGS_msgflag_read = new ExtendedPropertyDefinition(3591, MapiPropertyType.Integer);
message.SetExtendedProperty(PR_MESSAGE_FLAGS_msgflag_read, 1);
保存项目后,这些属性无法设置,因此在第一次Save
调用之前执行此操作非常重要。