发送E-mail的类,经测试,可以发送(推荐)
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Net.Mail;
using System.Net;
using System.IO;
namespace KuaiCan.Web
{
/// <summary>
/// 发送E-mail的类,经测试,可以发送(推荐)
/// </summary>
public class SendMail
{
public string SendEmail(string toAddr, string title, string content)
{
MailMessage msg = new MailMessage();
msg.To.Add(toAddr);
msg.To.Add("xxxxxxxxxx@163.com");
msg.CC.Add("xxxxxxxxxx@163.com");
msg.From = new MailAddress("xxxxxxxxxx@163.com", "Automation Mercer", System.Text.Encoding.UTF8);
msg.Subject = title;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = content;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = false;
msg.Priority = MailPriority.Normal;
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("xxxxxxxxxx@163.com", "密码");
client.Port = 25; //587, 465, 995
client.Host = "smtp.163.com";
//client.EnableSsl = true;
//object userState = msg;
try
{
client.Send(msg);
return "sucess";
}
catch (SmtpException ex)
{
return ex.Message + "SendEmail error";
}
}
}
}