/// <summary>
/// 发送邮件
/// </summary>
/// <param name="sendAdress">发送邮件地址</param>
/// <param name="receiveAdress">接收邮件地址,如有多个以,分隔</param>
/// <param name="Title">邮件标题</param>
/// <param name="Content">邮件内容</param>
/// <param name="pwd">发件人密码</param>
public static void SendMail(string sendAdress,string receiveAdress,string Title,string Content,string pwd)
{
//取出所有的收件人地址
string[] adressCollect = receiveAdress.Split(new Char[] { ',' });
foreach (string item in adressCollect)
{
MailMessage msg = new MailMessage(sendAdress, item);
//通过发送地址取出smtp地址
string[] service = sendAdress.Split(new Char[] { '@', '.' });
//组合smtp地址
string smtpAdress = "smtp." + service[1] + ".com";
SmtpClient smtpClient = new SmtpClient(smtpAdress);
//指示通过网络发送电子邮件
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
//身份验证
smtpClient.Credentials = new NetworkCredential(sendAdress, pwd);
//设置邮件标题和内容
msg.Subject = Title;
msg.Body = Content;
//发送邮件
try
{
smtpClient.Send(msg);
}
catch (Exception e)
{
throw e;
}
}
}