当前位置: 编程技术>.net/c#/asp.net
c#调用qq邮箱smtp发送邮件(修改版)
来源: 互联网 发布时间:2014-08-30
本文导语: c#调用qq邮箱发送邮件的方法。 代码: 代码示例: try { MailMessage mm = new MailMessage(); MailAddress Fromma = new MailAddress("xxxx@qq.com"); MailAddress Toma = new MailAddress("MMMMMMM@qq.com", null); mm.From = Fromma; //收件人 ...
c#调用qq邮箱发送邮件的方法。
代码:
代码示例:
try
{
MailMessage mm = new MailMessage();
MailAddress Fromma = new MailAddress("xxxx@qq.com");
MailAddress Toma = new MailAddress("MMMMMMM@qq.com", null);
mm.From = Fromma;
//收件人
mm.To.Add("MMMMMM@qq.com");
//邮箱标题
mm.Subject = "Hello Dear:";
mm.IsBodyHtml = true;
//邮件内容
mm.Body = "你好Mr流星!";
//内容的编码格式
mm.BodyEncoding = System.Text.Encoding.UTF8;
//mm.ReplyTo = Toma;
//mm.Sender =Fromma;
//mm.IsBodyHtml = false;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
mm.CC.Add(Toma);
SmtpClient sc = new SmtpClient();
NetworkCredential nc = new NetworkCredential();
nc.UserName = "XXXXX@qq.com";//你的邮箱地址
nc.Password = "zzzzz";//邮箱密码,xxxxx@qq.com邮箱的密码
sc.UseDefaultCredentials = true;
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Credentials = nc;
//如果这里报mail from address must be same as authorization user这个错误,是QQ邮箱没有开启SMTP,
//到自己邮箱设置。在帐户下面,如果是163邮箱,要修改为smtp.163.com
sc.Host = "smtp.qq.com";
sc.Send(mm);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
{
MailMessage mm = new MailMessage();
MailAddress Fromma = new MailAddress("xxxx@qq.com");
MailAddress Toma = new MailAddress("MMMMMMM@qq.com", null);
mm.From = Fromma;
//收件人
mm.To.Add("MMMMMM@qq.com");
//邮箱标题
mm.Subject = "Hello Dear:";
mm.IsBodyHtml = true;
//邮件内容
mm.Body = "你好Mr流星!";
//内容的编码格式
mm.BodyEncoding = System.Text.Encoding.UTF8;
//mm.ReplyTo = Toma;
//mm.Sender =Fromma;
//mm.IsBodyHtml = false;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
mm.CC.Add(Toma);
SmtpClient sc = new SmtpClient();
NetworkCredential nc = new NetworkCredential();
nc.UserName = "XXXXX@qq.com";//你的邮箱地址
nc.Password = "zzzzz";//邮箱密码,xxxxx@qq.com邮箱的密码
sc.UseDefaultCredentials = true;
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Credentials = nc;
//如果这里报mail from address must be same as authorization user这个错误,是QQ邮箱没有开启SMTP,
//到自己邮箱设置。在帐户下面,如果是163邮箱,要修改为smtp.163.com
sc.Host = "smtp.qq.com";
sc.Send(mm);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}