While working on a project which needs a configuration for sending email to clients for their confirmation regarding any topic or for sending mail for notifications or for any other reason, you might be looking for the code that can do this task for you. Here I will give you a code that you can use in your application for sending email.
Instructions:
- Add the following namespaces to your Code-Behind file.
using System.Net.Mail; using System.Net; using System.Configuration;
- Add the following lines of code in Code-Behind file where you want to send an email.
System.Net.Mail.MailMessage mail =
new System.Net.Mail.MailMessage("yourEmailId", "destinationEmailId");
mail.Subject = ""; //Enter the text for the subject of the mail in quotes. mail.Body = ""; //Enter the text for the body of mail within the quotes. mail.IsBodyHtml = true; SmtpClient client = new SmtpClient("smtp.gmail.com"); NetworkCredential cred = new NetworkCredential("yourEmailId", "yourPassword"); client.EnableSsl = true; client.Credentials = cred; try { client.Send(mail); } catch (Exception) { }
Incoming search terms:
- c# send email quoted text (1)
- latest working SMTP for gmail 2012 (1)
- send email with gmail c# (1)