Пожалуйста, определите ошибку в этом
Когда я запускаю этот код для отправки почты, я получаю такую ошибку:
"
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required" using System.Net.Mail; using System.Text; public partial class _Default : System.Web.UI.Page { /*User Crediatials by which Mail would sent */ private const String FROM = "my email"; private const String userName = FROM; private const String PassWord = "password of 8 chars"; private String MailTitle = ""; private String MailBody = ""; protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { try { SmtpClient client = new SmtpClient(); client.Port = 587; client.Host = "smtp.gmail.com"; client.EnableSsl= true; client.Timeout = 1000000; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = true; client.Credentials = new System.Net.NetworkCredential(userName,PassWord); MailTitle = "Test Mail Notification !"; MailBody = "This is a Simple Mail Tester !"; MailMessage mm = new MailMessage(FROM,TextBox3.Text,MailTitle,"<h1><u>"+ MailBody+"</u></h1>"); mm.IsBodyHtml = true;/*TO sebd HTML Formatted Data !*/ mm.BodyEncoding = UTF8Encoding.UTF8; mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; client.Send(mm); Response.Write("Mail Sent Successfully"); } catch (Exception ex) { Response.Write(ex.Message); }
Что я уже пробовал:
Я попробовал выше код, но я говорю "
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required
"
manu_dhobale
Попробуйте UseDefaultCredentials = false