ASP.Net电子邮件SmtpException问题

时间:2015-04-09 16:14:11

标签: asp.net email

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

  

错误详细信息:System.Net.Mail.SmtpException:SMTP服务器需要   安全连接或客户端未经过身份验证。服务器   回应是:不允许转发

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

我已使用Google实验室配置邮件。这是否会影响?

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");

1 个答案:

答案 0 :(得分:0)

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