I can't understand why this code is not working.
I have this error:
System.IO.IOException: Connection closed at System.Net.Mail.SmtpClient.Read ()
System.IO.IOException: Connection closed at System.Net.Mail.SmtpClient.SendCore
System.IO.IOException: Connection closed at System.Net.Mail.SmtpClient.SendInternal
System.IO.IOException: Connection closed at System.Net.Mail.SmtpClient.Send
static void Main(string[] args) { var smtp = new SmtpClient { DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, EnableSsl = true, Host = "smtp.gmail.com", //465 SSL se uso 25 solo ad utenti google mando Port = 465, Credentials = new NetworkCredential("id", "password"), }; Console.WriteLine("Mail From: "); var fromAddress = new MailAddress(Console.ReadLine()); Console.WriteLine("Mail To: "); var toAddress = new MailAddress(Console.ReadLine()); Console.WriteLine("Subject: "); string subject = Console.ReadLine(); Console.WriteLine("Body: "); string body = Console.ReadLine(); using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) try { smtp.Send(message); } catch(Exception ex) { Console.WriteLine("Unable to send message due to the following reason: " + ex.ToString()); } }
how can I solve these problems?