0

the email code works on local host but when i upload the website on server it shows error The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

//Formatted
protected void btnSend_Click(object sender, EventArgs e)
{

            var fromAddress = "djdanny1255@gmail.com";
              string email = "djdanny1255@gmail.com";
            var toAddress = email;
            const string fromPassword = "********";
            string subject = "Email=" + txtEmail.Text + "     Phone=" + txtMobile.Text;
            string body = txtMessage.InnerText;



            try
            {
                using (MailMessage mm = new MailMessage(fromAddress, email))
                {

                    mm.Subject = subject;
                    mm.Body = body;

                    mm.IsBodyHtml = false;
                    SmtpClient smtp = new SmtpClient();
                    smtp.Host = "smtp.gmail.com";
                    smtp.EnableSsl = true;
                    NetworkCredential NetworkCred = new NetworkCredential(fromAddress, fromPassword);
                    smtp.UseDefaultCredentials = true;
                    smtp.Credentials = NetworkCred;
                    smtp.Port = 587;
                    smtp.Send(mm);

                }
            }
            catch (Exception ex)
            {

                Response.Write("Error" + ex.Message);
            }
Ryan Wilson
  • 10,223
  • 2
  • 21
  • 40
  • 1
    https://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail?rq=1 – Nkosi Jul 05 '18 at 18:44
  • Also look [this](https://stackoverflow.com/questions/29958229/send-email-using-gmail-error-the-server-response-was-5-5-1-authentication-req) and [this](https://stackoverflow.com/questions/31978816/smtp-mail-with-asp-net-error-5-5-1-authentication-required) with similar issue. Google had implemented new security measure for email address. – Tetsuya Yamamoto Jul 06 '18 at 02:58
  • You need to check permissions for SMTP allowance on the server where you are hosting your site. Generally not every server permits the SMTP request and sometimes it blocks the IP. In most of such cases we need to permit and allow the Port numbers on host server. I hope it helps you. – Abhishek Sharma Jul 06 '18 at 04:34

1 Answers1

0

in first cas, i suggest you to change code at this code :

using (MailMessage mail = new MailMessage())
            {
                mail.From = new MailAddress(fromAddress);
                mail.To.Add(toAddress);
                mail.Subject = subject;
                mail.Body = body;
                mail.IsBodyHtml = true;
                using (SmtpClient smtp = new SmtpClient())
                {
                    smtp.Host = "smtp.gmail.com";
                    smtp.Port = 587;
                    smtp.EnableSsl = true;
                    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                    smtp.UseDefaultCredentials = false;
                    smtp.Credentials = new NetworkCredential(fromAddress,fromPassword);
                    smtp.Send(mail);
                }
            }

and second after your Login in to your email, CLICK HERE .

This will see this page enter image description here

i hope this help you ^^