/// <summary>
/// 单发Email
/// </summary>
/// <param name="from">发信人地址</param>
/// <param name="to">收信人地址</param>
/// <param name="title">标题</param>
/// <param name="body">内容</param>
/// <returns></returns>
public static string sendEmail(string to, string title, string body)
{
try
{
MailMessage m_message = new MailMessage();
m_message.From = new MailAddress("*@163.com");
m_message.To.Add(new MailAddress(to));
m_message.Subject = title;
m_message.Body = body;
SmtpClient m_smtpClient = createClient();
m_smtpClient.Send(m_message);
return "发送成功";
}
catch (Exception e)
{
return e.Message;
}
}
/// <summary>
/// 群发Email
/// </summary>
/// <param name="from">发信人地址</param>
/// <param name="to">收信人地址列表</param>
/// <param name="title">标题</param>
/// <param name="body">内容</param>
/// <returns></returns>
public static string sendEmail(string[] to, string title, string body)
{
try
{
MailMessage m_message = new MailMessage();
m_message.From = new MailAddress("*@163.com");
foreach (string s in to)
{
m_message.To.Add(new MailAddress(s));
}
m_message.Subject = title;
m_message.Body = body;
SmtpClient m_smtpClient =createClient();
m_smtpClient.Send(m_message);
return "发送成功";
}
catch (Exception e)
{
return e.Message;
}
}
public static SmtpClient createClient()
{
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.163.com";
smtp.Port = 25;
smtp.UseDefaultCredentials = true;//不能和帐号顺序颠倒,否则出错。
smtp.Credentials = new System.Net.NetworkCredential("*@163.com", "******");
return smtp;
}