带有 ASP.net 错误的 SMTP 邮件 5.5.1 需要身份验证
SMTP Mail with ASP.net Error 5.5.1 Authentication Required
美好的一天,我是使用 ASP.net 和 SMTP Mailer
的初学者
这是我的问题,我从本地发送电子邮件时总是遇到此错误
并在网上搜索并尝试了解决方案,但并不那么幸运,
我希望有人指出我需要什么代码以及我在哪里遇到这个错误
Message = "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at"
这是我的代码:
protected void btnSendEmail_Click(object sender, EventArgs e)
{
// System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0
// System.Net.Mail.SmtpClient is the alternate class for this in 2.0
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress(txtEmail.Value, txtName.Value);
smtpClient.Credentials = new System.Net.NetworkCredential("myUser@gmail", "password");
// You can specify the host name or ipaddress of your server
// Default in IIS will be localhost
smtpClient.Host = "smtp.gmail.com";
smtpClient.EnableSsl = true;
//Default port will be 25
smtpClient.Port = 25;
smtpClient.UseDefaultCredentials = false;
//From address will be given as a MailAddress Object
message.From = fromAddress;
// To address collection of MailAddress
message.To.Add("myEmail@gmail.com");
message.Subject = txtSubject.Value;
// CC and BCC optional
// MailAddressCollection class is used to send the email to various users
// You can specify Address as new MailAddress("admin1@yoursite.com")
message.CC.Add("myEmail@gmail.com");
// You can specify Address directly as string
message.Bcc.Add(new MailAddress("myEmail@gmail.com"));
//Body can be Html or text format
//Specify true if it is html message
message.IsBodyHtml = false;
// Message body content
message.Body = txtaMessage.Value;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.HeadersEncoding = System.Text.Encoding.UTF8;
// Send SMTP mail
smtpClient.Send(message);
lblSuccess.Text = "Email successfully sent.";
}
catch (Exception ex)
{
lblSuccess.Text = "Send Email Failed.";
}
}
试试这个参考资料ASP Simple SMTP for C# and VB它对我可能遇到的 smtp 问题有很大帮助
请查看 google 支持团队,了解他们对从应用程序发送邮件的看法。
https://support.google.com/mail/answer/78775?hl=en
另外关注link可以帮到你。
Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required
我试图制作一个简单的发送电子邮件的代码,试试这个
MailMessage mm = new MailMessage();
mm.From = new MailAddress("fromEmail");
mm.To.Add("toEmail");
mm.CC.Add("ccEmail");
mm.Subject = "StringSubject";
mm.Body = "BodySubject";
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "UsernameString";
NetworkCred.Password = "PasswordString";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
try
{
smtp.Send(mm);
}
catch (Exception)
{
}
转到 Gmail 帐户,然后 select
连接的应用程序和网站
允许安全性较低的应用程序:开(如果关闭,您将无法通过应用程序或您的网站发送邮件)
美好的一天,我是使用 ASP.net 和 SMTP Mailer
的初学者这是我的问题,我从本地发送电子邮件时总是遇到此错误 并在网上搜索并尝试了解决方案,但并不那么幸运, 我希望有人指出我需要什么代码以及我在哪里遇到这个错误
Message = "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at"
这是我的代码:
protected void btnSendEmail_Click(object sender, EventArgs e)
{
// System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0
// System.Net.Mail.SmtpClient is the alternate class for this in 2.0
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress(txtEmail.Value, txtName.Value);
smtpClient.Credentials = new System.Net.NetworkCredential("myUser@gmail", "password");
// You can specify the host name or ipaddress of your server
// Default in IIS will be localhost
smtpClient.Host = "smtp.gmail.com";
smtpClient.EnableSsl = true;
//Default port will be 25
smtpClient.Port = 25;
smtpClient.UseDefaultCredentials = false;
//From address will be given as a MailAddress Object
message.From = fromAddress;
// To address collection of MailAddress
message.To.Add("myEmail@gmail.com");
message.Subject = txtSubject.Value;
// CC and BCC optional
// MailAddressCollection class is used to send the email to various users
// You can specify Address as new MailAddress("admin1@yoursite.com")
message.CC.Add("myEmail@gmail.com");
// You can specify Address directly as string
message.Bcc.Add(new MailAddress("myEmail@gmail.com"));
//Body can be Html or text format
//Specify true if it is html message
message.IsBodyHtml = false;
// Message body content
message.Body = txtaMessage.Value;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.HeadersEncoding = System.Text.Encoding.UTF8;
// Send SMTP mail
smtpClient.Send(message);
lblSuccess.Text = "Email successfully sent.";
}
catch (Exception ex)
{
lblSuccess.Text = "Send Email Failed.";
}
}
试试这个参考资料ASP Simple SMTP for C# and VB它对我可能遇到的 smtp 问题有很大帮助
请查看 google 支持团队,了解他们对从应用程序发送邮件的看法。 https://support.google.com/mail/answer/78775?hl=en
另外关注link可以帮到你。
Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required
我试图制作一个简单的发送电子邮件的代码,试试这个
MailMessage mm = new MailMessage();
mm.From = new MailAddress("fromEmail");
mm.To.Add("toEmail");
mm.CC.Add("ccEmail");
mm.Subject = "StringSubject";
mm.Body = "BodySubject";
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "UsernameString";
NetworkCred.Password = "PasswordString";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
try
{
smtp.Send(mm);
}
catch (Exception)
{
}
转到 Gmail 帐户,然后 select 连接的应用程序和网站 允许安全性较低的应用程序:开(如果关闭,您将无法通过应用程序或您的网站发送邮件)