我正嘗試使用此代碼通過Gmail發送電子郵件:SMTPClient類錯誤
MailMessage msg = new MailMessage();
msg.From = new MailAddress("[email protected]");
msg.To.Add(destinos);
msg.Subject = "XXXX";
msg.Body = "XXXX"
//msg.Attachments.Add(new Attachment(archivo + ".pdf"));
//msg.Attachments.Add(new Attachment(archivo + ".xml"));
SmtpClient client = new SmtpClient("smtp.google.com", 587);//587 465
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new System.Net.NetworkCredential("[email protected]", pass);
client.Send(msg);
但是失敗了,給這個例外:
16/07/2012 03:45 p.m. ERROR: Error al enviar correo. Data: System.Collections.ListDictionaryInternal System.Net.WebException: No se puede resolver el nombre remoto: 'smtp.google.com'
en System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
en System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
en System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
en System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
en System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
en System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
en System.Net.Mail.SmtpClient.GetConnection()
en System.Net.Mail.SmtpClient.Send(MailMessage message) Exception actual: Void Send(System.Net.Mail.MailMessage)
唯一的例外是在西班牙,我不「噸真的很喜歡,要麼,但它說是這樣的:
There was an error when sending the mail, Couldn't resolve host smtp.google.com
我已經檢查了目前谷歌的參數和他們看起來好這段代碼。
我認爲這是smtp.gmail.c OM – 2012-07-16 21:01:13