邮件发送代码
protected void sendMail(string M_from, string[] M_to, string M_UserName, string M_Password)
{
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
//设置发件人地址
mailMessage.From = new System.Net.Mail.MailAddress(M_from);
//添加收件人地址
foreach (string to_mail in M_to)
{
mailMessage.To.Add(to_mail);
}
//mailMessage.To.Add("wangkyx@126.com");
//mailMessage.To.Add("644286730@qq.com");
//mailMessage.To.Add("Mary@sohu.com");
//邮件主题
mailMessage.Subject = "邮件主题";
//邮件正文
mailMessage.Body = "邮件正文";
//正文编码方式
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
//邮件正文是否为Html的值
mailMessage.IsBodyHtml = true;
//设置邮件发送的优先级
mailMessage.Priority = System.Net.Mail.MailPriority.Normal;
System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient();
//设置SMTP主机地址
mail.Host = "smtp.163.com";
//设置SMTP服务端口号
mail.Port = 25;
mail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
//设置是否使用默认的身份凭证
mail.UseDefaultCredentials = false;
//设置发件人的身份凭证(用户名和密码)
mail.Credentials = new System.Net.NetworkCredential(M_UserName, M_Password);
mail.Send(mailMessage);
}
{
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
//设置发件人地址
mailMessage.From = new System.Net.Mail.MailAddress(M_from);
//添加收件人地址
foreach (string to_mail in M_to)
{
mailMessage.To.Add(to_mail);
}
//mailMessage.To.Add("wangkyx@126.com");
//mailMessage.To.Add("644286730@qq.com");
//mailMessage.To.Add("Mary@sohu.com");
//邮件主题
mailMessage.Subject = "邮件主题";
//邮件正文
mailMessage.Body = "邮件正文";
//正文编码方式
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
//邮件正文是否为Html的值
mailMessage.IsBodyHtml = true;
//设置邮件发送的优先级
mailMessage.Priority = System.Net.Mail.MailPriority.Normal;
System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient();
//设置SMTP主机地址
mail.Host = "smtp.163.com";
//设置SMTP服务端口号
mail.Port = 25;
mail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
//设置是否使用默认的身份凭证
mail.UseDefaultCredentials = false;
//设置发件人的身份凭证(用户名和密码)
mail.Credentials = new System.Net.NetworkCredential(M_UserName, M_Password);
mail.Send(mailMessage);
}