您好
如何在配置多个邮件帐户时通过默认邮件帐户以编程方式在C#中发送Outlook邮件?
感谢
答案 0 :(得分:0)
默认帐户是什么意思? 如果您想使用该程序通过该帐户发送,并且您有一台交换服务器,您可以使用:
string exchangeServer;
public void SendMail(string recipient, string subject, string body)
{
var service = CreateService(recipient);
EmailMessage message = new EmailMessage(service);
message.Subject = subject;
message.Body = body;
message.ToRecipients.Add(recipient);
message.SendAndSaveCopy();
}
private ExchangeService CreateService(string recipient)
{
var service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Url = new Uri(exchangeServer);
service.Credentials = new WebCredentials(Credential.impersonateUser, Credential.impersonatePassword);
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, recipient);
service.HttpHeaders.Add("X-AnchorMailbox", recipient);
return service;
}