Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

c# - Failure sending mail via Google SMTP

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("[email protected]", "[email protected]")
                        {
                            Subject = "Testing subject",
                            Body = "Testing body"
                        };
            try
            {
                var client = new SmtpClient("smtp.google.com", 465)
                                {
                                    EnableSsl = true,
                                    Credentials = new NetworkCredential("[email protected]", "password")
                                };
                client.Send(mail);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 ([email protected] or username@your_domain.com)

    Password: your Gmail password


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...