-4
try
        {
            MailMessage mail = new MailMessage();
            mail.To.Add(UserName.Text);
            mail.From = new MailAddress("shammus672@gmail.com");
            mail.Subject = "Varificarion Code";
            string Body = "Hello";
            mail.Body = Body;
            mail.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new System.Net.NetworkCredential("shammus762@gmail.com", "shammus123");// Enter senders User name and password
            smtp.EnableSsl = true;
            smtp.Send(mail);
            return true;
        }
        catch (Exception ex)
        {
            string str = ex.ToString();
            return false;

        }

Exception: "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"

i want to send varification mail to user.

Abubakar
  • 97
  • 8
  • Read [ask] and try searching before asking a new question. – CodeCaster Dec 17 '16 at 13:38
  • that question not solve my problem. i am not receving confirmation email.. – Abubakar Dec 17 '16 at 14:19
  • 1
    Have you followed the directions in the question CodeCaster linked to? You haven't said what you've done in your question, so I assume not, and so closing this question as a duplicate of that one is appropriate. – mason Dec 17 '16 at 14:40

1 Answers1

-1

Try this;

1- add these namespaces to your project;

using System.Net.Mail;

using System.Net;

2- Use this code phrase;

    MailMessage mail = new MailMessage();
    mail.IsBodyHtml = true;
    mail.To.Add(UserName.Text.ToString());

    mail.From = new MailAddress("shammus672@gmail.com", "Hello", System.Text.Encoding.UTF8);
    mail.Subject = "Verification Code";
    string Mesaj = "Hello";
    mail.Body = Mesaj;

    SmtpClient smtp = new SmtpClient();
    smtp.Credentials = new NetworkCredential("shammus762@gmail.com", "shammus123");
    smtp.Port = 587;
    smtp.Host = "smtp.gmail.com";
    smtp.EnableSsl = true;
    if (UserName.Text.ToString() != string.Empty)
    {
        smtp.Send(mail);
    }