通过c#的WebMail帐户发送邮件

本文关键字:WebMail 通过 | 更新日期: 2023-09-27 18:03:42

我有一个域,我已经上传我的ASP。. NET MVC网站,也使用cpanel我已经创建了一些邮件帐户。现在当我试图发送电子邮件,我得到错误。看看我的代码::

MailMessage message = new MailMessage();
message.From = new MailAddress("webmail-ac@domain.com");
message.To.Add("example@hotmail.com");
message.Subject = "Welcome.";
message.IsBodyHtml = true;
message.Body = "this is my test email body";
SmtpClient smtpClient = new SmtpClient();
smtpClient.UseDefaultCredentials = true;
smtpClient.Host = "Domain-IP";
smtpClient.Port = 25;
smtpClient.EnableSsl = true;
smtpClient.Credentials = new System.Net.NetworkCredential("webmail-ac@domain.com", "Password");
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, 
    X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtpClient.Send(message);

但是我得到下面描述的错误::

服务不可用,正在关闭传输通道。日志含义服务器的响应是:Cannot connect to SMTP server [domain-ip] ([domain-ip]:25), connect error 10060.

有谁能帮我解决这个问题吗?

通过c#的WebMail帐户发送邮件

请在凭据的上方添加下面一行,并尝试是否有帮助:

smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;