View Categories

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

2 min read

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);

Here is Some Solutions :

Solution 1: #

MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(“smtp.gmail.com”);
mail.From = new MailAddress(“fromaddress@gmail.com”);
mail.To.Add(“toaddress1@gmail.com”);
mail.To.Add(“toaddress2@gmail.com”);
mail.Subject = “Password Recovery “;
mail.Body += ” <html>”;
mail.Body += “<body>”;
mail.Body += “<table>”;
mail.Body += “<tr>”;
mail.Body += “<td>User Name : </td><td> HAi </td>”;
mail.Body += “</tr>”;

mail.Body += “<tr>”;
mail.Body += “<td>Password : </td><td>aaaaaaaaaa</td>”;
mail.Body += “</tr>”;
mail.Body += “</table>”;
mail.Body += “</body>”;
mail.Body += “</html>”;
mail.IsBodyHtml = true;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential(“sendfrommailaddress.com”, “password”);
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);

Solution 2: #

Public Shared Sub enviaDB(ByRef body As String, ByRef file_location As String)
Dim mail As New MailMessage()
Dim SmtpServer As New SmtpClient(“smtp.gmail.com”)
mail.From = New MailAddress(“from@gmail.com”)
mail.[To].Add(“to@gmail.com”)
mail.Subject = “subject”
mail.Body = body
Dim attachment As System.Net.Mail.Attachment
attachment = New System.Net.Mail.Attachment(file_location)
mail.Attachments.Add(attachment)
SmtpServer.Port = 587
SmtpServer.Credentials = New System.Net.NetworkCredential(“user”, “password”)
SmtpServer.EnableSsl = True
SmtpServer.Send(mail)
End Sub

Solution 3: #

var fromAddress = new MailAddress(asd@asd.com, “From Name”);
var toAddress = new MailAddress(“tosend@asd.com”, “To Name”);

const string subject = “Subject”;
const string body = “Body”;

var smtp = new SmtpClient
{
Host = “aspmx.l.google.com”,
Port = 25,
EnableSsl = false
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *

Privacy Settings
We use cookies to enhance your experience while using our website. If you are using our Services via a browser you can restrict, block or remove cookies through your web browser settings. We also use content and scripts from third parties that may use tracking technologies. You can selectively provide your consent below to allow such third party embeds. For complete information about the cookies we use, data we collect and how we process them, please check our Privacy Policy
Youtube
Consent to display content from Youtube
Vimeo
Consent to display content from Vimeo
Google Maps
Consent to display content from Google
Spotify
Consent to display content from Spotify
Sound Cloud
Consent to display content from Sound