C# 如何通过ExchangeService C发送电子邮件#

C# 如何通过ExchangeService C发送电子邮件#,c#,exchange-server,C#,Exchange Server,我必须通过Exchange发送电子邮件。我发现我可以使用ExchangeService来实现这一点。我已经尝试了很多方法来实现这一点,但唯一得到的是错误:(440)登录超时 我甚至不知道凭据是否有问题,或者我的代码是否错误 string login = @"login"; string password = @"password"; ExchangeService service = new ExangeService(); service.Credentials = new NetworkCr

我必须通过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);
}

您是否尝试登录到quarkpol@gmail.com使用您在代码中输入的凭据联机?我假定
ExangeService
的拼写错误不是您的问题。拼写错误不是问题。我从服务器管理员那里得到的是登录名和密码。登录名不是电子邮件地址。这只是一个登录(一个字)。我还有服务器的地址,它是mail.exchangemail.com。@quarkpol您是否尝试过按照此处的文档进行操作?我认为问题在于您的帐户权限问题。