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