asp.net SmtpClient发送邮件的代码
本文导语: asp.net stmpClient邮件发送实例。 代码示例: using System.Net.Mail /// /// 邮件发送 ///by http://www. /// /// public bool Send() { //mail message MailMessage myMail = new MailMessage(); myMail.From = new MailAddress("发送邮箱@163.com"); ...
asp.net stmpClient邮件发送实例。
using System.Net.Mail
///
/// 邮件发送
///by http://www.
///
///
public bool Send()
{
//mail message
MailMessage myMail = new MailMessage();
myMail.From = new MailAddress("发送邮箱@163.com"); // 发送人
myMail.To.Add(new MailAddress("接收邮箱@163.com")); // 接收人邮箱
myMail.Subject = "测试邮件发送--主题";
myMail.SubjectEncoding = Encoding.UTF8;
myMail.Body = "测试邮件发送--正文";
myMail.BodyEncoding = Encoding.UTF8;
myMail.IsBodyHtml = false;
myMail.Priority = MailPriority.Normal; // 邮件级别
//myMail.CC.Add(new MailAddress("test@163.com")); // 抄送
//myMail.Bcc.Add(new MailAddress("test@163.com")); // 密送
//Smtp Client
SmtpClient sender = new SmtpClient();
sender.Host = "smtp.163.com";// email.Host;
//sender.Port = 80;
// 设置发送人的邮箱和密码
sender.Credentials = new NetworkCredential("发送邮箱@163.com","邮箱密码");
sender.DeliveryMethod = SmtpDeliveryMethod.Network;
sender.EnableSsl = false; // 是否启用 SSL 加密
try
{
sender.Send(myMail);
return true;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}