Note that there are some explanatory texts on larger screens.

plurals
  1. POGmail: How to send an email programmatically
    primarykey
    data
    text
    <h2>Possible Exact Duplicate: <a href="https://stackoverflow.com/questions/32260/sending-email-in-c-net-through-gmail">Sending Email in C#.NET Through Gmail</a></h2> <p>Hi,</p> <p>I'm trying to send an email using gmail:</p> <p>I tried various examples that I found on this site and other sites but I always get the same error:<br> Unable to connect to the remote server -- > System.net.Sockets.SocketException: No connection could be made because the target actively refused it 209.85.147.109:587</p> <pre><code> public static void Attempt1() { var client = new SmtpClient("smtp.gmail.com", 587) { Credentials = new NetworkCredential("MyEmailAddress@gmail.com", "MyPassWord"), EnableSsl = true }; client.Send("MyEmailAddress@gmail.com", "some.email@some.com", "test", "testbody"); } </code></pre> <p>Any ideas?</p> <p><strong>UPDATE</strong></p> <p>More details.</p> <p>Maybe I should say what other attempts I made that gave me the same error: (Note when i didn't specify a port it tryed port 25)</p> <pre><code> public static void Attempt2() { var fromAddress = new MailAddress("MyEmailAddy@gmail.com", "From Name"); var toAddress = new MailAddress("MyEmailAddy@dfdf.com", "To Name"); const string fromPassword = "pass"; const string subject = "Subject"; const string body = "Body"; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, 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); } } public static void Attempt3() { MailMessage mail = new MailMessage(); mail.To.Add("MyEmailAddy@dfdf.com"); mail.From = new MailAddress("MyEmailAddy@gmail.com"); mail.Subject = "Email using Gmail"; string Body = "Hi, this mail is to test sending mail" + "using Gmail in ASP.NET"; mail.Body = Body; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Credentials = new System.Net.NetworkCredential ("MyEmailAddy@gmail.com", "pass"); smtp.EnableSsl = true; smtp.Send(mail); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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