0

このコードを使用してGmail経由でメールを送信しようとしています。

MailMessage msg = new MailMessage();
            msg.From = new MailAddress("admin@XXXXXX.com");
            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("admin@XXXX.com", 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

私は現在のグーグルパラメータをチェックしました、そしてそれらはこのコードによく見えます。

4

3 に答える 3

1

コードでdmainを解決できません。smtp.GMAIL.comである必要があります

見る:

http://support.google.com/mail/bin/answer.py?hl=en&answer=13287

于 2012-07-16T21:05:23.300 に答える
1

以下のグーグルからのifnromationを参照してください。SMTPホストが間違っているようです http://support.google.com/mail/bin/answer.py?hl=en&answer=13287

Configure your client to match the settings below:
Incoming Mail (POP3) Server - requires SSL: pop.gmail.com
Use SSL: Yes
Port: 995
Outgoing Mail (SMTP) Server - requires TLS3 
    or SSL: smtp.gmail.com (use authentication)
Use Authentication: Yes
Port for TLS/STARTTLS: 587
Port for SSL: 465
Account Name:   your full email address (including @gmail.com or @your_domain.com)
Email Address:  your email address (username@gmail.com or username@your_domain.com)
Password:   your Gmail password
于 2012-07-16T21:06:56.977 に答える
1
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);

(ふぅ)

于 2012-07-16T21:11:29.557 に答える