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

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

mail sending with network credential as true in windows form not working

gmail uses port 587 oClient.Port = 587; You may also want to set UseDefaultCredentials to false and explicitly declare username and password. By declaring it to be true, you are trying to log into your gmail account using your windows credentials. oClient.UseDefaultCredentials = false; oClient.Credentials = new NetworkCredential(“[email protected]”, “password”); Also, in gmail security, you will … Read more

Why do I get “‘property cannot be assigned” when sending an SMTP email?

mail.To and mail.From are readonly. Move them to the constructor. using System.Net.Mail; … MailMessage mail = new MailMessage(“[email protected]”, “[email protected]”); SmtpClient client = new SmtpClient(); client.Port = 25; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Host = “smtp.gmail.com”; mail.Subject = “this is a test email.”; mail.Body = “this is my test email body”; client.Send(mail);