Has anyone had any experience creating basic contact form to send to an office 365 account?
I am getting the following error when I try to submit the form with the send method as below…
Error in processing. The server response was: 5.7.3 STARTTLS is required to send mail [LO4P123CA0177.GBRP123.PROD.OUTLOOK.COM]
My method look like this…
private void SendEmail(ContactShowroomModel model)
{
string userName = "my-username";
string password = "my-password";
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("my-email-address"));
msg.From = new MailAddress(userName);
msg.Subject = $"Website enquiry from Name: { model.Name} | Email Address: { model.Email}";
msg.Body = model.Message;
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential(userName, password);
client.UseDefaultCredentials = false;
client.Host = "smtp.office365.com";
client.EnableSsl = false;
client.TargetName = "STARTTLS/smtp.office365.com";
client.Port = 587;
client.Send(msg);
}
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/104420-573-starttls-is-required-to-send-mail