Categories:

The following C# source code shows how to send an email from a Gmail address using the SMTP server.

using System.Net.Mail;
MailMessage objeto_mail = new MailMessage();
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("username", "password");
objeto_mail.From = new MailAddress("from@example.com");
objeto_mail.To.Add(new MailAddress("to@example2.com"));
objeto_mail.Subject = "Subject here";
objeto_mail.Body = "Message here";
client.Send(objeto_mail);

Tags:

420 Responses

Leave a Reply