CopyPastor

Detecting plagiarism made easy.

Score: -1; Reported for: Open both answers

Possible Plagiarism

Plagiarized on 2018-02-16
by Liquid Core

Original Post

Original - Posted on 2009-01-28
by Donny V.



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Try this:
**Note** Be sure to use System.Net.Mail, not the deprecated System.Web.Mail. Doing SSL with System.Web.Mail is a gross mess of hacky extensions.
using System.Net; using System.Net.Mail; var fromAddress = new MailAddress("from@gmail.com", "From Name"); var toAddress = new MailAddress("to@example.com", "To Name"); const string fromPassword = "fromPassword"; 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); }
The above answer doesn't work. You have to set `DeliveryMethod = SmtpDeliveryMethod.Network` or it will come back with a "**client was not authenticated**" error. Also it's always a good idea to put a timeout.
Revised code:
using System.Net.Mail; using System.Net;
var fromAddress = new MailAddress("from@gmail.com", "From Name"); var toAddress = new MailAddress("to@yahoo.com", "To Name"); const string fromPassword = "password"; const string subject = "test"; const string body = "Hey now!!";
var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, Credentials = new NetworkCredential(fromAddress.Address, fromPassword), Timeout = 20000 }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); }

        
Present in both answers; Present only in the new answer; Present only in the old answer;