ABa*_*rto 11 c# ews-managed-api
我正在使用EWS Managed 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();
Run Code Online (Sandbox Code Playgroud)
如何代表其他用户发送邮件?:)
自从我摆弄同样的事情已经有一段时间了,我得出的结论是,尽管有"发送为"的权利,但这是不可能的.
模拟是使用EWS的唯一方法,请参阅MSDN:
ExchangeService service = new ExchangeService();
service.UseDefaultCredentials = true;
service.AutodiscoverUrl("app@domain.com");
// impersonate user e.g. by specifying an SMTP address:
service.ImpersonatedUserId = new ImpersonatedUserId(
ConnectingIdType.SmtpAddress, "user@domain.com");
Run Code Online (Sandbox Code Playgroud)
如果未启用模拟,则必须代表您要执行操作的用户提供用户凭据.请参阅此MSDN文章.
ExchangeService service = new ExchangeService();
service.Credentials = new NetworkCredential("user", "password", "domain");
service.AutodiscoverUrl("user@domain.com");
Run Code Online (Sandbox Code Playgroud)
或者,您只需指定回复地址即可.
EmailMessage mail = new EmailMessage(service);
mail.ReplyTo.Add("user@email.com");
Run Code Online (Sandbox Code Playgroud)
但是,使用System.Net.Mail发送邮件时,"发送为"权限确实适用,在许多情况下,只需发送电子邮件即可.有很多例子说明了如何做到这一点.
// create new e-mail
MailMessage mail = new MailMessage();
mail.From = new MailAddress("user@domain.com");
mail.To.Add(new MailAdress("recipient@somewhere.com"));
message.Subject = "Subject of e-mail";
message.Body = "Content of e-mail";
// send through SMTP server as specified in the config file
SmtpClient client = new SmtpClient();
client.Send(mail);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13016 次 |
| 最近记录: |