using System.Web.Mail;
// Mail initialization
MailMessage mailMsg = new MailMessage();
mailMsg.From = "test@test.com";
mailMsg.To = "desti@126.com";
//mailMsg.Cc = cc;
//mailMsg.Bcc = bcc;
mailMsg.Subject = "send mail use gmail";
mailMsg.BodyFormat = MailFormat.Text;
mailMsg.Body = "Hello here comes the sun";
mailMsg.Priority = MailPriority.High;
// Smtp configuration
SmtpMail.SmtpServer = "smtp.gmail.com";
// - smtp.gmail.com use smtp authentication
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "yourgmailaddress");
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "youpassword");
// - smtp.gmail.com use port 465 or 587
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
// - smtp.gmail.com use STARTTLS (some call this SSL)
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
// try to send Mail
try
{
SmtpMail.Send(mailMsg);
Response.Write("send success");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
// Mail initialization
MailMessage mailMsg = new MailMessage();
mailMsg.From = "test@test.com";
mailMsg.To = "desti@126.com";
//mailMsg.Cc = cc;
//mailMsg.Bcc = bcc;
mailMsg.Subject = "send mail use gmail";
mailMsg.BodyFormat = MailFormat.Text;
mailMsg.Body = "Hello here comes the sun";
mailMsg.Priority = MailPriority.High;
// Smtp configuration
SmtpMail.SmtpServer = "smtp.gmail.com";
// - smtp.gmail.com use smtp authentication
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "yourgmailaddress");
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "youpassword");
// - smtp.gmail.com use port 465 or 587
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
// - smtp.gmail.com use STARTTLS (some call this SSL)
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
// try to send Mail
try
{
SmtpMail.Send(mailMsg);
Response.Write("send success");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}