您的位置:首页 > 大数据 > 人工智能

如何使用gmail发送邮件

2008-03-07 11:39 549 查看
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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: