1 using System.Net.Mail;//添加邮件提醒
2 using System.Net;
3
4
5
6 privatevoid SendMail(string fromMail, string toMail, string subJect, string body, string userName,string passWord, string smtpHost)
7 {
8
9 //设置邮件信息 发件人地址、收件人地址、标题、邮件内容
10 MailMessage mail =new MailMessage(fromMail, toMail, subJect, body);
11 mail.ReplyTo =new MailAddress(fromMail);
12 //设置邮件主题格式
13 mail.BodyEncoding = System.Text.Encoding.UTF8;
14 //设置邮件主体格式是否为 html 格式
15 mail.IsBodyHtml =true;
16 //邮件优先级别
17 mail.Priority = MailPriority.High;
18 //设置发送邮箱的smtp服务器或安全端口
19 SmtpClient client =new SmtpClient(smtpHost);
20 //验证邮件服务器的身份
21 NetworkCredential work =new System.Net.NetworkCredential(userName, passWord);
22 client.Credentials = work;
23 //设置邮件发送格式
24 client.DeliveryMethod = SmtpDeliveryMethod.Network;
25 //是否请求一起发送
26 client.UseDefaultCredentials =true;
27 //安全连接设置
28 client.EnableSsl =false; //一定要为false 或者去掉这句 !不然报服务器不支持安全连接 也就是客户端没有开通SSL加密 所以以后都不要管!
29 try
30 {
31 client.Send(mail);
32 Response.Write("发送成功");
33 }
34 catch (Exception ex)
35 {
36 Response.Write(ex.Message +" 请联系管理员。");
37 }
38 }
39
40
41
42
43 调用代码:SendMail("frank@163.com", "1262510777@qq.com", "标题", "邮件内容", "frank", "qin10191789808", "smtp.163.com");