1 /// <summary> 2 /// 发送 3 /// </summary> 4 /// <param name="Subject">邮件标题</param> 5 /// <param name="Body">邮件正文</param> 6 /// <param name="mailTo">接收邮箱</param> 7 /// <param name="IsBodyHtml">是否是HTML格式</param> 8 /// <returns></returns> 9 private bool Send(string Subject, string Body, string mailTo, bool IsBodyHtml = false) 10 { 11 12 string smtpServer = "smtp.163.com"; //SMTP服务器 13 string mailFrom = "XXXX@163.com"; //登陆用户名,邮箱 14 string userPassword = "xxxx";//注意授权码 不是登录密码 15 SmtpClient smtpClient = new SmtpClient(); 16 smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式 17 smtpClient.Host = smtpServer; //指定SMTP服务器 18 smtpClient.Credentials = new System.Net.NetworkCredential(mailFrom, userPassword);//用户名和密码 19 // 发送邮件设置 20 MailMessage mailMessage = new MailMessage(mailFrom, mailTo); // 发送人和收件人 21 mailMessage.Subject = Subject;//主题 22 mailMessage.Body = Body;//内容 23 mailMessage.BodyEncoding = Encoding.UTF8;//正文编码 24 mailMessage.IsBodyHtml = IsBodyHtml;//设置为HTML格式 25 mailMessage.Priority = MailPriority.Low;//优先级 26 27 try 28 { 29 smtpClient.Send(mailMessage); // 发送邮件 30 return true; 31 } 32 catch (SmtpException ex) 33 { 34 return false; 35 } 36 }