码迷,mamicode.com
首页 > Web开发 > 详细

.NET 发送邮件

时间:2015-09-15 21:41:51      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

//邮件配置
public static string mail_smtp = System.Configuration.ConfigurationManager.AppSettings["mail_smtp"];
public static string mail_main = System.Configuration.ConfigurationManager.AppSettings["mail_main"];
public static string mail_pwd = System.Configuration.ConfigurationManager.AppSettings["mail_pwd"];
public static int mail_port = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["mail_port"]);
public static string mail_ssl = System.Configuration.ConfigurationManager.AppSettings["mail_ssl"];

 

/// <summary>
/// 发送邮件1
/// </summary>
/// <param name="AcceptEmail"></param>
/// <param name="sendText"></param>
public static void SendEmail(string AcceptEmail, string sendText, string SendTitle)
{
SendSMTPEMail(mail_smtp, mail_main, mail_pwd, AcceptEmail, SendTitle, sendText);
}
/// <summary>
/// 发送邮件2
/// </summary>
/// <param name="strSmtpServer"></param>
/// <param name="strFrom"></param>
/// <param name="strFromPass"></param>
/// <param name="strto"></param>
/// <param name="strSubject"></param>
/// <param name="strBody"></param>
public static void SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody)
{
SmtpClient client = new SmtpClient(strSmtpServer);
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Port = mail_port;
client.EnableSsl = mail_ssl == "yes";

MailMessage message = new MailMessage(strFrom, strto, strSubject, strBody);
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
client.Send(message);
}

.NET 发送邮件

标签:

原文地址:http://www.cnblogs.com/xsj1989/p/4811363.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!