File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments