string smtpAddress = "smtp.gmail.com"; int portNumber = 587; bool enableSSL = true; string emailFrom = "xyz@gmail.com"; string password = "myPassword"; string emailTo = "xyz@yahoo.com"; string subject = "Hello"; string body = "Hello, I'm just writing this to say Hi!"; using (MailMessage mail = new MailMessage()) { mail.From = new MailAddress(emailFrom); mail.To.Add(emailTo); mail.Subject = subject; mail.Body = body; mail.IsBodyHtml = true; // Can set to false, if you are sending pure text. mail.Attachments.Add(new Attachment("C:\\n.txt")); using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber)) { smtp.Credentials = new NetworkCredential(emailFrom, password); smtp.EnableSsl = enableSSL; smtp.Send(mail); } }
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Authentication required
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)