3

I am trying to send confirmation email to user using smtp provided by google and test in my local machine. I have written the code and supply the settings.

SmtpClient client = SiteUtilites.GetMailClient(); 

            MailAddress sender = new MailAddress(coreEmail, coreDisplayName);
            MailAddress receiver = new MailAddress(model.EmailAddress, model.Firstname + " " +model.Lastname);
            MailAddressCollection collection = new MailAddressCollection();

            MailMessage mailMessage = new MailMessage(sender, receiver);
            mailMessage.IsBodyHtml = true;
            mailMessage.Body = "Hello";
            client.Send(mailMessage);

This is the setting I have below

String smtpServer = ConfigurationManager.AppSettings["smtpServer"];
        String smtpUsername = ConfigurationManager.AppSettings["smtpUsername"];
        String smtpPassword = ConfigurationManager.AppSettings["smtpPassword"];
        String smtpPort = ConfigurationManager.AppSettings["smtpPort"];

        SmtpClient sc = new SmtpClient(smtpServer);
        NetworkCredential nc = new NetworkCredential(smtpUsername, smtpPassword);
        sc.UseDefaultCredentials = false;
        sc.Credentials = nc;
        sc.EnableSsl = true;
        sc.Port = 587;

Do I need my site to run in https ? I just want to test my script in my local machine.

This is the error it gives me

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

LittleFunny
  • 8,155
  • 15
  • 87
  • 198
  • 1
    Google may block sign in attempts from some apps or devices when you try to login from some app. Check this answer for more details:http://stackoverflow.com/a/32475872/2946329 – Salah Akbari Nov 26 '15 at 08:57

1 Answers1

0

It's possible that you are using weak password or using the default credentials. see following links for more details:

Community
  • 1
  • 1
Moradnejad
  • 3,466
  • 2
  • 30
  • 52