vcs vcs - 8 days ago 6
C# Question

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

I am using following code to send email. The Code works correctly in my local Machine. But on Production server i am getting the error message

var fromAddress = new MailAddress("mymailid@gmail.com");
var fromPassword = "xxxxxx";
var toAddress = new MailAddress("yourmailid@yourdoamain.com");

string subject = "subject";
string body = "body";

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)

};

using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})


smtp.Send(message);


And on my Gmail A/c I have received the following email after i ran the code from production server


Hi ,

Someone recently used your password to try to sign in to your Google
Account mymailid@gmail.com. This person was using an application such
as an email, client or mobile device.

We prevented the sign-in attempt in case this was a hijacker trying to
access your account. Please review the details of the sign-in attempt:

Friday, 3 January 2014 13:56:08 o'clock UTC IP Address: xxx.xx.xx.xxx
(abcd.net.) Location: Philadelphia PA, Philadelphia, PA, USA

If you do not recognise this sign-in attempt, someone else might be
trying to access your account. You should sign in to your account and
reset your password immediately.

Reset password

If this was you and you are having trouble accessing your account,
complete the troubleshooting steps listed at
http://support.google.com/mail?p=client_login

Yours sincerely, The Google Accounts team

Answer

This generally happens when you try login from different time zone or IP Address Computer. Your production server and the mail id you have used both are in different time zone. Choose any of the one solution:

1) 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 and log out.

Or 2) log in gmail to your local computer, Follow this Link and choose review this activity and take proper actions.