未能通过谷歌SMTP发送邮件 [英] Failure sending mail via Google SMTP

查看:906
本文介绍了未能通过谷歌SMTP发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然得到发送邮件失败。例外。该内部异常是无法连接到远程服务器和该内部异常是A连接尝试失败,因为连接的方没有正确一段时间后响应或已建立的连接失败,因为连接主机未能响应。我敢肯定,这个原因是不是防火墙设置。有谁知道我能做些什么呢?谢谢你。

  VAR邮件= MAILMESSAGE新(username@gmail.com,destination@gmail.cz)
{
=主题测试主题,
体=检测机构
};

{
VAR的客户=新SmtpClient(smtp.google.com,465)
{
EnableSsl = TRUE,
=证书新的NetworkCredential(username@gmail.com,密码)
};
client.Send(邮件);
}
赶上(异常前)
{
Console.WriteLine(ex.Message);
}


解决方案

下面是需要谷歌设置




  • 接收邮件(POP3)服务器 - 需要SSL:pop.gmail.com



    使用SSL:是的。



    端口:995



    发送邮件(SMTP)服务器 - 需要TLS3或SSL:smtp.gmail.com
    (使用验证)



    使用验证:是



    端口为TLS / STARTTLS:587



    SSL的端口:465



    帐户名:完整的电子邮件地址(包括@ gmail.com或
    @ your_domain.com)



    电子邮件地址:您的电子邮件地址(username@gmail.com或
    的用户名@ your_domain.com)



    密码:您的Gmail密码



I'm still getting "Failure sending mail." exception. The inner exception is "Unable to connect to the remote server" and the inner exception of that is "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". I'm pretty sure the cause of this is not the firewall setting. Does anyone know what I can do about it? Thanks.

var mail = new MailMessage("username@gmail.com", "destination@gmail.cz")
                        {
                            Subject = "Testing subject",
                            Body = "Testing body"
                        };
            try
            {
                var client = new SmtpClient("smtp.google.com", 465)
                                {
                                    EnableSsl = true,
                                    Credentials = new NetworkCredential("username@gmail.com", "password")
                                };
                client.Send(mail);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

解决方案

Here is the Google settings needed:

  • 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

这篇关于未能通过谷歌SMTP发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆