SmtpClient client = new SmtpClient("smtp.gmail.com");
NetworkCredential LoginInfo = new NetworkCredential("email@gmail.com", "password");
client.UseDefaultCredentials = false;
client.Credentials = LoginInfo;
MailMessage mail = new MailMessage();
mail.From = new MailAddress("email@gmail.com", "Alert mail");
mail.To.Add(new MailAddress(m.EmailId, "name or .."));
mail.Subject = "Welcome Letter or subject";
mail.Body = "Your message body, you can include html formating";
mail.IsBodyHtml = true;
model.EmailId = model.EmailId;
model.ETo = m.EmailId;
try
{
client.Send(mail);
model.IsActive = true;
Erepo.Add(model);
Erepo.Save();
}
catch (SmtpException sm)
{
model.IsActive = false;
Erepo.Add(model);
Erepo.Save();
}
If your application is hosted on shared server use
localhost instead of
smtp.gmail.com