自从我摆弄同样的事情以来,我已经有一段时间了,我认为这是不可能的,尽管有“发送”权限。
模拟是去与EWS唯一的出路,看到MSDN:
ExchangeService service = new ExchangeService();
service.UseDefaultCredentials = true;
service.AutodiscoverUrl("[email protected]");
// impersonate user e.g. by specifying an SMTP address:
service.ImpersonatedUserId = new ImpersonatedUserId(
ConnectingIdType.SmtpAddress, "[email protected]");
如果没有启用模拟,你必须提供用户代表谁的要采取行动的凭据。见this MSDN article。
ExchangeService service = new ExchangeService();
service.Credentials = new NetworkCredential("user", "password", "domain");
service.AutodiscoverUrl("[email protected]");
或者,您可以简单地指定一个reply-to address。
EmailMessage mail = new EmailMessage(service);
mail.ReplyTo.Add("[email protected]");
然而,“发送”权利做使用System.Net.Mail,这在很多情况下,只是发送电子邮件会做得很好发送邮件时适用。有tons of examples说明how to do this。
// create new e-mail
MailMessage mail = new MailMessage();
mail.From = new MailAddress("[email protected]");
mail.To.Add(new MailAdress("[email protected]"));
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);
mail.ReplyTo将无法正常工作,也没有二传手这一点。 public EmailAddressCollection ReplyTo {get; } – RobDigital
对,它是一个集合。所以你需要做'mail.ReplyTo.Add(“[email protected]”)' - 我会修正上面的例子。 – bernhof
使用模拟我在mail.send上得到一个错误。 - 引用邮箱时必须指定主SMTP地址 – markthewizard1234