0

back to my previous question. I am still have problem with sending email by Gmail SMTP. Previously i had error that:

Failure sending mail.

But now i changed some code and now i have his error:

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 64.233.167.109:465

I was so pissed off, that I started using wireshark to understand where the problem.

Here is what i found:

smtp.gmail.com Server: 53.90.35.60 Address: 53.90.35.60#53

Non-authoritative answer: smtp.gmail.com canonical name = gmail-smtp-msa.l.google.com. Name: gmail-smtp-msa.L.google.com Address: 64.233.167.108 Name: gmail-smtp-msa.L.google.com Address: 64.233.167.109

so as I understand there is response received from mail smtp server

Also we use proxy in our intranet, but I added proxy in my application, inside Web.config:

<system.net>
<defaultProxy enabled="true">
  <proxy proxyaddress="proxy_was_here" bypassonlocal="true"
  />
</defaultProxy>

and here is the part of new code:

var fromAddress = new MailAddress("email", "From Name");
                    var toAddress = new MailAddress("email", "To Name");
                    const string fromPassword = "pass";
                    const string subject = "Subject";
                    const string body = "Body";

                    var smtp = new SmtpClient
                    {
                        Host = "smtp.gmail.com",
                        Port = 465,
                        EnableSsl = true,
                        DeliveryMethod = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = false,
                        Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
                    };
                    using (var message = new MailMessage(fromAddress, toAddress)
                    {
                        Subject = subject,
                        Body = body
                    })
                    {
                        smtp.Send(message);
                    }

If you have any questions, please look at my previous question or just write in the comments below.

Bogdan Zubar
  • 73
  • 12

1 Answers1

0

Please try with port number 587 and EnableSSL = false

var smtp = new SmtpClient
{
   Host = "smtp.gmail.com",
   Port = 587,
   EnableSsl = true,
   DeliveryMethod = SmtpDeliveryMethod.Network,
   UseDefaultCredentials = false,
   Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
 };

also check with your credentials in https://www.smtper.net/

and also allow for less secure app from this link : https://myaccount.google.com/lesssecureapps?pli=1

  • That really weird it doesn't work at all (Gmail and Yahoo) – Bogdan Zubar Aug 16 '18 at 07:11
  • please try this, MailMessage mail = new MailMessage(from, to); mail.Subject = "Subject"; mail.Body = "Body";//Console.ReadLine(); SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.Credentials = new NetworkCredential("email-id", "password"); smtp.EnableSsl = true; smtp.Send(mail); if you body not contains any HTML code then set isHtmlBody = false; – Akhatarali Ansari Aug 16 '18 at 07:23
  • I turned on less secure app also in yahoo and it works on this website. But still doesn't work in my app. SMTP host: smtp.mail.yahoo.com Port: 587 Use SLL: True Use Authentication: True – Bogdan Zubar Aug 16 '18 at 07:27