[英]How to send an email, via ExchangeService C#
我必须通过 Exchange 发送电子邮件。 我发现我可以使用ExchangeService
做到这一点。 我已经尝试了很多方法来做到这一点,但只有我得到的是错误:(440) 登录超时。
我什至不知道是凭证有问题,还是我的代码有问题。
string login = @"login";
string password = @"password";
ExchangeService service = new ExangeService();
service.Credentials = new NetworkCredential(login, password);
service.Url = new Uri(@"https://mail.exchangemail.com");
EmailMessage message = new EmailMessage(service);
message.Subject = "Interesting";
message.Body = "The proposition has been considered.";
message.ToRecipients.Add("quarkpol@gmail.com");
message.From = "quarkpol_test@gmail.com";
message.Send();
我在网上找到了problrm 解决方案,它有效。
using EASendMail;
string login = @"login";
string password = @"password";
SmtpMail oMail = new SmtpMail("TryIt");
SmtpClient oSmtp = new SmtpClient();
oMail.From = "from@email.com";
oMail.To = "to@email.com";
oMail.AddAttachment(fileName, fileByteArray);
oMail.Subject = "Subject";
oMail.HtmlBody = "HTMLBody";
SmtpServer oServer = new SmtpServer("mail.email.com");
oServer.Protocol = ServerProtocol.ExchangeEWS;
oServer.User = login;
oServer.Password = password;
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
try
{
Console.WriteLine("start to send email ...");
oSmtp.SendMail(oServer, oMail);
Console.WriteLine("email was sent successfully!");
}
catch (Exception ep)
{
Console.WriteLine("failed to send email with the following error:");
Console.WriteLine(ep.Message);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.