Here is my code:
try
{
MailMessage m = new MailMessage
("[email protected]",
"[email protected]",
"Quarterly data report.",
"Hello, world.");
SmtpClient client = new SmtpClient("smtp.gmail.com", 465);
client.Credentials = new NetworkCredential("[email protected]", "password");
client.EnableSsl = true;
client.Send(m);
Console.WriteLine("sent");
}
catch (InvalidOperationException ey)
{
Console.WriteLine(ey.Message);
}
catch (SmtpFailedRecipientException sm)
{
Console.WriteLine(sm.Message);
}
catch (SmtpException ex)
{
Console.WriteLine(ex.Message);
}
This code produce this error at SmtpException: "Failure sending mail." The full is exception is this:
ex.ToString() "System.Net.Mail.SmtpException: Failure sending mail.
---> System.Net.WebException: Unable to connect to the remote server
---> System.Net.Sockets.SocketException: A connection attempt failed because
the connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to respond
74.125.67.109:587
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)\r\n at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
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 ConsoleApplication3.Program.Main(String[] args) in c:\\users\\alan\\documents\\visual studio 2010\\Projects\\ConsoleApplication3\\ConsoleApplication3\\Program.cs:line 24" string