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.