如何使用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);
}
// 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);
}
相关文章推荐
- 如何在 Linux 上使用 Gmail SMTP 服务器发送邮件通知
- 如何在 Linux 上使用 Gmail SMTP 服务器发送邮件通知
- 如何使用GMAIL的SMTP发送邮件
- 如何在 Laravel 中使用 SMTP 发送邮件(适用于 163、QQ、Gmail 等)
- 如何在 Laravel 中使用 SMTP 发送邮件(适用于 163、QQ、Gmail 等)
- 如何使用GMAIL的SMTP发送邮件
- python - 如何通过GMail发送邮件:smtplib的使用
- 如何使用GMail发送邮件
- 如何在 Laravel 中使用 SMTP 发送邮件(适用于 163、QQ、Gmail 等)
- 如何在FOXMAIL上使用GMAIL接送/发送邮件
- 如何使用GMAIL的SMTP发送邮件
- 如何在 Laravel 中使用 SMTP 发送邮件(适用于 163、QQ、Gmail 等)
- python - 如何通过GMail发送邮件:smtplib的使用
- 如何在 Laravel 中使用 SMTP 发送邮件(适用于 163、QQ、Gmail 等)
- 如何在ASP.NET中使用SmtpMail发送邮件
- 告广讯全体同事,如何将现有的使用Gmail绑定的2opp.net企业邮箱的邮件,转移到 绑定QQ的2opp.net的企业邮箱里面
- 配置ActionMailer使用GMail发送邮件
- 使用CakePHP自带Email组件通过gmail发送邮件
- Linux 上使用 Gmail SMTP 服务器发送邮件通知
- 如何使用SAP发送邮件?