這裏是我的代碼:.NET爲什麼我無法發送電子郵件?
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);
}
此代碼在SmtpException產生此錯誤: 「發送郵件失敗。」 全是例外的是:
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
接受你的其他問題的一些答案,或者人們會不太願意幫助你。 – 2010-10-11 16:48:31
您的防火牆和網絡邊界的防火牆是否在正確的端口上打開? – 2010-10-11 16:49:33
我不能,我需要一些聲譽去做 – Alan 2010-10-11 16:49:38