Note that there are some explanatory texts on larger screens.

plurals
  1. POSend Email via Google Apps in C#
    text
    copied!<p>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. </p> <p>I am receiving the following exception: "The operation has timed out."</p> <p>My code is below:</p> <pre><code> //Create the mail message MailMessage mail = new MailMessage(); //Set the addresses mail.From = new MailAddress("myemail@gmail.com", "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); </code></pre> <p>My web.config has the following settings:</p> <pre><code> &lt;smtp from="myemail@gmail.com" deliveryMethod="Network"&gt; &lt;network host="smtp.gmail.com" userName="myemail@gmail.com" password="password" port="587" /&gt; &lt;/smtp&gt; </code></pre> <p>During my troubleshooting I have tried:</p> <ul> <li>Using my personal gmail address as well as another from a domain hosted through Google Apps.</li> <li>Using ports 25, 465, and 587</li> <li>Hard coding the config settings in the c# code instead of using the web.config</li> <li>Sending and telneting from multiple network locations to ensure the firewall/ISP was not blocking it</li> <li>Ensured that POP was enabled in the GMail settings (according to Google this should turn on the ability to send using SMTP)</li> <li>Changing the send from and replyTo address to ensure they match the account (apparently a GMail necessity).</li> </ul> <p>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 # <a href="https://stackoverflow.com/questions/757987/send-email-via-c-through-google-apps-account">757987</a> to no avail. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload