Click here to Skip to main content
14,330,512 members
Rate this:
Please Sign up or sign in to vote.
See more:
when working in the application it is working fine and receiving mail. when it is hosted message sending failed and i am getting the error like "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"

My code is :

public void SendVerificationLinkEmail(string emailID, string activationCode)
    var verifyUrl = "/User/VerifyAccount/" + activationCode;
    var link = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, verifyUrl);

    var fromEmail = new MailAddress("<hidden>", "Jyoti Looks Good");
    var toEmail = new MailAddress(emailID);
    var fromEmailPassword = "********"; // Replace with actual password
    string subject = "Your account is successfully created!";

    string body = "We are excited to tell you that your Dotnet Awesome account is" + " successfully created. Please click on the below link to verify your account" +"<a href="" + link + "">" + link + "</a> ";

    var smtp = new SmtpClient()
        Host = "",
        Port = 587,
        EnableSsl = true,
        DeliveryMethod = SmtpDeliveryMethod.Network,
        UseDefaultCredentials = false,
        Credentials = new NetworkCredential(fromEmail.Address, fromEmailPassword)

    using (var message = new MailMessage(fromEmail, toEmail)
        Subject = subject,
        Body = body,
        IsBodyHtml = true

What I have tried:

Please help me to solve this issue
Updated 9-Oct-19 22:02pm
Richard MacCutchan 10-Oct-19 4:01am
Don't try to use gmail, use your local email server.
Afzaal Ahmad Zeeshan 10-Oct-19 4:02am
If you have passed down correct Gmail username/password, this code would work just fine, can you try using the port 25 for this and see how that works?
F-ES Sitecore 10-Oct-19 4:15am
This is one of the most frequently asked questions. Google for how to send mail through gmail and you should not only find the code but the non-code things you have to do too such as give access to your account. Note that you can't "relay" through gmail, the "from" address has to match the credentials you are using. One of the many reasons not to use gmail for sending email.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100