Делаю так:
public static void SendEmailAsync(string email, string subject, string message)
{
MailMessage mail = new MailMessage("***@gmail.com",email);
mail.Body = message;
mail.Subject = subject;
SmtpClient smtp = new SmtpClient("smtp.gmail.com",465);
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential("***@gmail.com", "mypass");
try
{
smtp.Send(mail);
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}
}
}
Вылетает в catch
с сообщением
{System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: The connection was closed. at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at site.EmailService.SendEmailAsync(String email, String subject, String message) in C:\Users\Виталий\source\repos\site\site\EmailService.cs:line 64}
Помогите разобраться в чем проблема