0

I am using MVC framework 4.5 C# and publish the my project on Windows server 2012 R2. In that server when I tried to sending mail with gmail but its can not send the mail and giving the below description.

The SMTP server requires a secure connection or the client was not authenticated.The server response was: 5.5.1 Authentication Required.

I installed SMTP Service and all configuration regarding that.

Same mail configuration is running my development server.

full-stack
  • 553
  • 5
  • 20
Himanshu N Tatariya
  • 268
  • 1
  • 8
  • 26
  • what code are you using to send the email? – jonaChaz Jun 26 '19 at 13:38
  • 2
    Possible duplicate of [Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required](https://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not) – derpirscher Jun 26 '19 at 13:39

2 Answers2

0

It is due to security check on gmail so please follow below steps.

  • Log in to production server via remote access, and sign in to gmail once with your credentials. They will ask for the confirmation, confirm it
Himanshu N Tatariya
  • 268
  • 1
  • 8
  • 26
0
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Credentials = new System.Net.NetworkCredential("your email address", "password");
client.Port = 587;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
// Specify the email sender.
// Create a mailing address that includes a UTF8 character
// in the display name.
MailAddress from = new MailAddress("your email address");
// Set destinations for the email message.
MailAddress to = new MailAddress(textBox_SedToEmail.Text);
// Specify the message content.
MailMessage message = new MailMessage(from, to);
message.Body = "This is a test email message sent by an application. ";
// Include some non-ASCII characters in body and subject.
string someArrows = new string(new char[] { '\u2190', '\u2191', '\u2192', '\u2193' });
message.Body += Environment.NewLine + someArrows;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = "test message 1" + someArrows;
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.Attachments.Add(new Attachment(@"C:\Users\eddie\Pictures\2.jpg"));
// Set the method that is called back when the send operation ends.
client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
// The userState can be any object that allows your callback
// method to identify this send operation.
// For this example, the userToken is a string constant.
string userState = "test message1";

client.SendAsync(message, userState);
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68