EWS 托管 API:如何设置电子邮件的发件人?
我正在使用 EWS 托管 API 发送电子邮件。帐户“account@domain.com”具有“发送为”权限,可以使用“sender@domain.com”邮箱发送邮件(从 Outlook 可以正常工作)。
但我尝试从代码中 - 这是行不通的,在邮件中,我在“发件人”“account@domain.com”字段中读到。
....
EmailMessage message = new EmailMessage(service);
message.Body = txtMessage;
message.Subject = txtSubject;
message.From = txtFrom;
....
message.SendAndSaveCopy();
如何代表其他用户发送邮件? :)
I'm using EWS Managed API to sending email. Account "account@domain.com" have permissions "Send as" to use "sender@domain.com" mailbox to send messages (from Outlook, it's work fine).
But I try from code - it's not work, in mail i'm read in the field "From" "account@domain.com".
....
EmailMessage message = new EmailMessage(service);
message.Body = txtMessage;
message.Subject = txtSubject;
message.From = txtFrom;
....
message.SendAndSaveCopy();
How to make sending mail on behalf of another user? :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经有一段时间没有摆弄同样的事情了,我的结论是,尽管拥有“发送为”权限,但这是不可能的。
模拟是使用 EWS 的唯一方法,请参阅 MSDN:
如果未启用模拟,您必须提供您想要代表的用户的凭据。请参阅这篇 MSDN 文章。
或者,您可以简单地指定 回复地址。
但是,使用 System.Net.Mail 发送邮件时,“发送为”权限确实适用,在许多情况下,仅发送电子邮件时就可以了。有大量示例说明如何执行此操作。
It's been a while since I fiddled with the same thing, and I concluded that it isn't possible, in spite of having "Send as" rights.
Impersonation is the only way to go with EWS, see MSDN:
If impersonation isn't enabled, you'll have to supply the credentials of the user on behalf of whom you want to act. See this MSDN article.
Alternatively you can simply specify a reply-to address.
However, "Send as" rights do apply when sending mail using System.Net.Mail, which in many cases will do just fine when just sending e-mails. There are tons of examples illustrating how to do this.
我认为您应该使用
Sender
属性,以便您的代码应如下所示:i think you should use the
Sender
property so the your code should look like: