Hi,
Today a quick Code Snippet in order to Send Emails using your Google Gmail Account with C#
static void Main(string[] args)
{
SmtpClient smtp = new SmtpClient();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("MyAccount@gmail.com", "MyPassword");
MailMessage mail = new MailMessage();
MailAddress MailFrom = new MailAddress("me@me.com", "Me");
MailAddress MailTo = new MailAddress("you@you.com", "You");
mail.To.Add(MailTo);
mail.From = MailFrom;
mail.Sender = MailFrom;
mail.Subject = "Mail Test Using Gmail";
mail.IsBodyHtml = true;
StringBuilder sb = new StringBuilder();
sb.Append("<html><head></head><body>");
sb.Append("<strong>Hello World !</strong>");
sb.Append("</body></html>");
mail.Body = sb.ToString();
try
{
smtp.Send(mail);
Console.WriteLine("Mail Sent !");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
Views(1080)

