-5

How to solve this SMTP Error problem? When I'm sending mail I'm facing this error message. Sending mail using local system is not a problem. Does anyone know the solution to this problem?

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at admin_booking.btninvoicemail_Click(Object sender, EventArgs e) in c:\inetpub\vhosts\starlineroadways.com\httpdocs\admin_booking.aspx.cs:line 596 code:

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential("xx@gmail.com", "xx");  
System.Net.Mail.MailMessage oMsg = new System.Net.Mail.MailMessage();
MailAddress @add = new MailAddress(txtsendemail.Text);  
oMsg.From = new MailAddress("xx");
oMsg.To.Add(@add);
oMsg.Subject = "xxx";
oMsg.Body = msgbody2;
oMsg.IsBodyHtml = true;
smtp.Send(oMsg);
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
user3259635
  • 51
  • 1
  • 12
  • 2
    Please provide the relevant code.. – Matthijs May 30 '14 at 09:47
  • Is IIS configured correctly with the mail server details? – TZHX May 30 '14 at 09:47
  • 2
    Welcome to SO! Clearly, "Authentication Required" is the problem as the error says. Do share the code in the **relevant** code behind `admin_booking.aspx.cs` so people can see if you are missing something (which you are, authentication). – Candide May 30 '14 at 09:48
  • 1
    http://www.codeproject.com/Questions/644799/The-SMTP-server-requires-a-secure-connection-or-th – Shubhojit May 30 '14 at 09:53

1 Answers1

0

You can try this.

MailMessage Mail = new MailMessage();
Mail.From = new MailAddress("xx@gmail.com");
Mail.To.Add(txtsendemail.Text);
Mail.Subject = "xxx";
Mail.Body = msgbody2;
SmtpClient smpt = new SmtpClient();
smpt.Credentials = new NetworkCredential("xx@gmail.com", "xx");
smpt.Port = 587;
smpt.Host = "smtp.gmail.com";
smpt.EnableSsl = true;
smpt.Send(Mail);
TKsknl
  • 71
  • 2
  • 9