ASP.Net电子邮件SmtpException问题



当我尝试使用asp.net发送邮件时,我会收到以下错误。

错误详细信息:System.Net.Mail.SMTP异常:SMTP服务器需要安全连接或客户端未通过身份验证。服务器响应为:不允许中继

我使用了正确的凭据(通过它我们可以访问网络邮件)

我已经使用谷歌实验室配置了邮件。这会影响吗

MailMessage mailMsg = new MailMessage();
mailMsg.From = new MailAddress("info@thewebsite.com", "thewebsite.com");
mailMsg.To.Add(new MailAddress(ToAddress));
mailMsg.Subject = Subject;
mailMsg.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");

System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString
(System.Text.RegularExpressions.Regex.Replace(BodyText, @"<(.|n)*?>", string.Empty), null, "text/plain");
System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(BodyText, null, "text/html");
mailMsg.AlternateViews.Add(plainView);
mailMsg.AlternateViews.Add(htmlView);

// Smtp configuration
SmtpClient smtp = new SmtpClient();
smtp.UseDefaultCredentials = true;
string smtphost = System.Configuration.ConfigurationManager.AppSettings["smtphost"].ToString();
int smtpport = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["smtpport"].ToString());

smtp.Host = smtphost; 
smtp.Port = smtpport;  

smtp.Credentials = new System.Net.NetworkCredential("info@thewebsite.com", "pwd1234");

我认为u必须设置smtp.EnableSsl = true;

最新更新