【发布时间】:2018-11-21 17:20:26
【问题描述】:
我正在尝试创建一封电子邮件并将其保存到当前工作正常的用户草稿文件夹中。但是,该电子邮件有一个巨大的“收件人”字段,当用户从他们的草稿文件夹发送电子邮件时,该电子邮件无法正确发送。有任何想法吗?这个问题似乎只出现在 Outlook 2016 中。这是我目前的保存方法。
public void Save(string saveToEmailAddress, string recipient, string subject, IEnumerable<MailAttachment> attachments)
{
try
{
// We need to impersonate the User whose account we are adding a Draft email to
_exchangeService.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, saveToEmailAddress);
var email = new EmailMessage(_exchangeService)
{
Subject = subject
};
email.ToRecipients.Add(recipient);
foreach (var attachment in attachments)
{
email.Attachments.AddFileAttachment(attachment.FileName, attachment.Content);
}
email.Save();
}
finally
{
// Stop impersonating the User account
// If this doesn't happen, any email sent from this Service
// will appear to be coming from the Impersonated account (not the Intranet)
_exchangeService.ImpersonatedUserId = null;
}
}
【问题讨论】:
-
看起来你的
recipient参数可能有一些你需要去掉的空格?可能应该指定您将其保存到代码中的草稿文件夹,以便更明确地说明它在做什么。email.Save(WellKnownFolderName.Drafts); -
是的,你是对的。在某些情况下,我添加了导致问题的空白收件人。
-
亲爱的,很高兴你把它整理好了 :-)
标签: c# .net email outlook exchangewebservices