簡體   English   中英

如何通過 ExchangeService C# 發送電子郵件

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM