首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SMTPClient类错误

SMTPClient类错误
EN

Stack Overflow用户
提问于 2012-07-17 04:59:09
回答 3查看 2.3K关注 0票数 0

我正在尝试使用以下代码通过gmail发送一封电子邮件:

代码语言:javascript
复制
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);

然而,它失败了,给出了这个异常:

代码语言:javascript
复制
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)

例外是西班牙语,我也不太喜欢,但它是这样写的:

代码语言:javascript
复制
There was an error when sending the mail, Couldn't resolve host smtp.google.com

我已经检查了当前的google参数,它们看起来对这段代码很好。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-07-17 05:06:57

请看下面来自谷歌的信息,看起来你把smtp主机的http://support.google.com/mail/bin/answer.py?hl=en&answer=13287弄错了。

代码语言:javascript
复制
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
票数 1
EN

Stack Overflow用户

发布于 2012-07-17 05:05:23

您的代码无法解析dmain。应为smtp.GMAIL.com

请参见:

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

票数 1
EN

Stack Overflow用户

发布于 2012-07-17 05:11:30

代码语言:javascript
复制
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);

(呼)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11512464

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档