Good morning,
In this post, I want to show a simple code that demonstrate how to send a email in ASP.NET application via a GMail account.
Now, open Visual Studio 2005/2008 and create new ASP.NET project.
Declare this assembly below:
using System.Net; using System.Net.Mail;
Use this function, modify if needed
public static bool SendMail(string to) { MailMessage mail = new MailMessage(); mail.To.Add(to); mail.Bcc.Add(new MailAddress("someone@domain.com")); mail.Subject = "Welcome to MicroSYNC Blog !"; mail.IsBodyHtml = true; // if you want to use HTML tags string str = "Dear Mr.AD," + "Thank you for your member registering at MicroSYNC Blog...Blabblablalaa"; mail.Body = str; try { SmtpClient client = new SmtpClient(); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = true; client.Host = "smtp.gmail.com"; client.Port = 587; // setup Smtp authentication string GMailAccount = "no-reply@microsync.net"; string password = "sYyT%r#$&frdfHGy45764565f%TG$%%^DFS#$FDTYt"; // Very strong password :) NetworkCredential credentials = new NetworkCredential(GMailAccount, password); client.UseDefaultCredentials = false; client.Credentials = credentials; client.Send(mail); return true; } catch (Exception) { return false; } } } }
That ’s really simple ?

