Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

58 строки
2.4 KiB

3 лет назад
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Web;
  4. using System.Net.Mail;
  5. /// <summary>
  6. /// 发送邮件
  7. /// </summary>
  8. namespace Basic.Tools
  9. {
  10. public class Mail
  11. {
  12. /// <summary>
  13. /// 发送邮件(smtp服务器/发送邮箱/邮箱密码/接收邮箱/发件人名称/邮件标题/邮件内容)
  14. /// </summary>
  15. /// <param name="_Host"></param>
  16. /// <param name="_from"></param>
  17. /// <param name="_pwd"></param>
  18. /// <param name="_tomail"></param>
  19. /// <param name="_senderDisplayName"></param>
  20. /// <param name="_Subject"></param>
  21. /// <param name="_Body"></param>
  22. /// <returns></returns>
  23. public static bool Send(string _Host, string _from, string _pwd, string _tomail, string _senderName, string _Subject, string _Body)
  24. {
  25. bool Result = false;
  26. try
  27. {
  28. //创建smtpclient对象
  29. System.Net.Mail.SmtpClient client = new SmtpClient();
  30. client.Host = _Host;//163的smtp服务器是 smtp.163.com
  31. client.UseDefaultCredentials = false;
  32. client.Credentials = new System.Net.NetworkCredential(_from, _pwd);
  33. client.DeliveryMethod = SmtpDeliveryMethod.Network;
  34. System.Text.Encoding encoding = System.Text.Encoding.UTF8;
  35. MailAddress mailfrom = new MailAddress(_from, _senderName, encoding);//发件人邮箱地址,名称,编码UTF8
  36. MailAddress mailto = new MailAddress(_tomail, "A", encoding);//收件人邮箱地址,名称,编码UTF8
  37. //创建mailMessage对象
  38. System.Net.Mail.MailMessage message = new MailMessage(mailfrom, mailto);
  39. message.Subject = _Subject;
  40. //正文默认格式为html
  41. message.Body = _Body;
  42. message.IsBodyHtml = true;
  43. message.BodyEncoding = encoding;
  44. message.SubjectEncoding = encoding;
  45. //message.HeadersEncoding = encoding;
  46. client.Send(message);
  47. Result = true;
  48. }
  49. catch (Exception ex)
  50. {
  51. string e = ex.Message.ToString();
  52. Result = false;
  53. }
  54. return Result;
  55. }
  56. }
  57. }