/// <summary>
/// 发送邮件
/// </summary>
/// <param name="toEmailS">邮件接收者列表</param>
/// <param name="titleEmail">邮件标题</param>
/// <param name="bodyEmail">邮件主体(内容)</param>
public void SendMail(string strEmail, string titleEmail, string bodyEmail)
{
string from = "EmailName@163.com"; //指定发送方的账户名
string server = "smtp.163.com"; //指定发送方使用的邮件服务器
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(server);
//指定发送方登录邮箱的用户名和密码
client.Credentials = new System.Net.NetworkCredential("EmailName", "EmailPwd");
//指定电子邮件的发送方式, 枚举值, 有三种方式, 这里使用网络方式
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
string[] toEmailS = strEmail.Split(',');
foreach (string str in toEmailS)
{
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, str, titleEmail, bodyEmail);
try
{
client.Send(message);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
return;
} }
client.Dispose(); //释放连接
}