大步前行

不管前方有什么,好在有人支持,大步向前走就对了

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
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);
}
posted on 2008-03-07 11:39  大步前行  阅读(1316)  评论(2编辑  收藏  举报