冒充没有邮箱时如何发送带附件的邮件

我有一项服务作为机器上的预定作业运行。它在没有自己邮箱的服务帐户下运行。我们希望它从团队的共享收件箱发送电子邮件。

在这里使用模拟是我尝试过的。


var service = new ExchangeService

{

    TraceEnabled = true,

    ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, Resources.EmailUsername)

};


service.AutodiscoverUrl(Resources.EmailUsername, RedirectionUrlValidationCallback);


var email = new EmailMessage(service);


if (!string.IsNullOrWhiteSpace(recipients))

{

    foreach (var recipient in recipients.Split(','))

    {

        email.ToRecipients.Add(recipient.Trim());

    }

}


email.Subject = subject;

email.Body = new MessageBody(BodyType.HTML, body);


if (attachmentName != null && attachment != null)

{

    email.Attachments.AddFileAttachment(attachmentName, attachment);                        

}


email.Send();

它失败了,我收到一个异常说:


当作为没有邮箱的帐户提出请求时,您必须为任何可分辨文件夹 Id 指定邮箱主 smtp 地址。


偶然的你
浏览 134回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP