自從我擺弄同樣的事情以來,我已經有一段時間了,我認爲這是不可能的,儘管有「發送」權限。
模擬是去與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