I have been trying to send Email in Asp.Net Core 3.1.But I always keep on getting this error System.Net.Mail.SmtpException: Server does not support secure connections.
My Source Code-
- var fromAddress = new MailAddress("[email protected]", "Atulya Raj");
- var toAddress = new MailAddress("[email protected]", "Name");
- const string fromPassword = "password";
- const string subject = "Test";
- string body = "Hello"
- var smtp = new SmtpClient
- {
- Host = "smtp.gmail.com",
- Port = 587,
- EnableSsl = true,
- DeliveryMethod = SmtpDeliveryMethod.Network,
- UseDefaultCredentials = false,
- Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
- };
- using (var message = new MailMessage(fromAddress, toAddress)
- {
- Subject = subject,
- Body = body
- })
- {
- smtp.Send(message);
- }
Any help would be nice.Thanks.