// <summary>
/// 发送邮件
/// </summary>
/// <param name="fromemail">发件人邮箱</param>
/// <param name="pwd">发件人密码</param>
/// <param name="toemail">收件人邮箱</param>
/// <param name="subject">主题</param>
/// <param name="body">内容</param>
/// <returns></returns>
public static bool SendEmail(string fromemail, string pwd, string toemail, string subject, string body)
{
SmtpClient client = new SmtpClient();
client.Host = "smtp." + fromemail.Remove(0, fromemail.IndexOf("@") + 1);
client.UseDefaultCredentials = false;
if (client.Host == "smtp.gmail.com")
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential(fromemail, pwd);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage message = new MailMessage(fromemail, toemail);
message.Subject = subject;
message.Body = body;
message.IsBodyHtml = true;
message.BodyEncoding = Encoding.UTF8;
message.Headers.Add("X-Priority", "3");
message.Headers.Add("X-MSMail-Priority", "Normal");
message.Headers.Add("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869");
message.Headers.Add("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2869");
message.Headers.Add("ReturnReceipt", "1");
try
{
client.Send(message);
return true;
}
catch (Exception)
{
return false;
}
}
发件人的邮箱QQ邮箱、163邮箱都是可以的,gmail邮箱调用这个方法不行,邮箱的内容是包括HTML格式,有关内容中的字体大小,颜色或者链接等,需转成HTML格式再发送