I am trying to send a basic email through Google Apps/Gmail using C# (System.Net.Mail/Framework 4) and I am having trouble doing so.
I am receiving the following exception: "The operation has timed out."
My code is below:
//Create the mail message
MailMessage mail = new MailMessage();
//Set the addresses
mail.From = new MailAddress("[email protected]", "My Name");
mail.To.Add(Email);
//Set the subject and bodycontent
mail.Subject = "Email Testing";
mail.Body = "This is the body of the email";
//Send the message using the SmtpClient
SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = true;
smtp.Send(mail);
My web.config has the following settings:
<smtp from="[email protected]" deliveryMethod="Network">
<network host="smtp.gmail.com"
userName="[email protected]"
password="password"
port="587" />
</smtp>
During my troubleshooting I have tried:
I am able to send and receive email fine through the GMail interface for both of my email accounts. I have also tried the settings and solutions offered in Question # 757987 to no avail.
Your code looks fine. You say you tried Telneting. Were you actually able to send an email through telnet?
You could try removing
from="[email protected]" deliveryMethod="Network"
from your smtp tag since they aren't necessary for what you're doing.
EDIT:
Telnet will normally allow you to connect to the smtp server and send 16 (?) bytes of data before it will kick you out. If you aren't getting responses like these, then this is likely the case.
Try opening up port 587 on your firewall and see if you can actually interact with the smtp server via telnet (EHLO, ECHO, etc.).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With