Skip to content

Commit 0504a89

Browse files
liyafeiliyafei
authored andcommitted
Create TestSendEmail.cs
1 parent 89dab7e commit 0504a89

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

TestSendEmail.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net.Mail;
5+
using System.Text;
6+
7+
namespace TestSendEmail
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
14+
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
15+
msg.To.Add("devgis@qq.com");
16+
/*
17+
* msg.CC.Add("c@c.com");
18+
* msg.CC.Add("c@c.com");可以抄送给多人
19+
*/
20+
msg.From = new MailAddress("邮箱", "AlphaWu", System.Text.Encoding.UTF8);
21+
/* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/
22+
msg.Subject = "这是测试邮件html";//邮件标题
23+
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
24+
msg.Body = "<a href='http://www.devgis.com'>devgis</a>";//邮件内容
25+
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
26+
msg.IsBodyHtml = true;//是否是HTML邮件
27+
msg.Priority = MailPriority.High;//邮件优先级
28+
SmtpClient client = new SmtpClient();
29+
client.Credentials = new System.Net.NetworkCredential("邮箱", "密码");
30+
//在zj.com注册的邮箱和密码
31+
client.Host = "smtp.163.com";
32+
object userState = msg;
33+
try
34+
{
35+
client.SendAsync(msg, userState);
36+
//简单一点儿可以client.Send(msg);
37+
Console.WriteLine("发送成功");
38+
}
39+
catch (System.Net.Mail.SmtpException ex)
40+
{
41+
Console.WriteLine("发送邮件出错:"+ ex.Message);
42+
}
43+
Console.Read();
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)