Sending email fails when two factor authentication is on for Gmail

Create a custom app in you Gmail security settings. Log-in into Gmail with your account Navigate to https://security.google.com/settings/security/apppasswords In ‘select app’ choose ‘custom’, give it an arbitrary name and press generate It will give you 16 chars token. Use the token as password in combination with your full Gmail account and two factor authentication will … Read more

SmtpClient with Gmail

Gmail’s SMTP server requires you to authenticate your request with a valid gmail email/password combination. You do need SSL enabled as well. Without actually being able to see a dump of all your variables being passed in the best guess I can make is that your Credentials are invalid, make sure you’re using a valid … Read more

C# SmtpClient class not able to send email using gmail

You won’t believe what fixed my problem. The Credentials property ss.Credentials = new NetworkCredential(“username”, “pass”); must be declared after ss.UseDefaultCredentials = false; So the final working code listing is SmtpClient ss = new SmtpClient(“smtp.gmail.com”, 587); ss.EnableSsl = true; ss.Timeout = 10000; ss.DeliveryMethod = SmtpDeliveryMethod.Network; ss.UseDefaultCredentials = false; ss.Credentials = new NetworkCredential(“username”, “pass”); MailMessage mm = … Read more

How to send email using simple SMTP commands via Gmail?

to send over gmail, you need to use an encrypted connection. this is not possible with telnet alone, but you can use tools like openssl either connect using the starttls option in openssl to convert the plain connection to encrypted… openssl s_client -starttls smtp -connect smtp.gmail.com:587 -crlf -ign_eof or connect to a ssl sockect directly… … Read more

What are best practices for using SmtpClient, SendAsync and Dispose under .NET 4.0

The original question was asked for .NET 4, but if it helps as of .NET 4.5 SmtpClient implements async awaitable method SendMailAsync. As a result, to send email asynchronously is as the following: public async Task SendEmail(string toEmailAddress, string emailSubject, string emailMessage) { using (var message = new MailMessage()) { message.To.Add(toEmailAddress); message.Subject = emailSubject; message.Body … Read more

tech