c # stmp mailing

 

        Recently used to send the e-mail function, because stmp settings, parameter passing errors are some problems take a detour, although the code is very simple, here is the record about for next inspection.

1, sent a personal email test

. 1      class Program
 2      {
 . 3          static  void the Main ( String [] args)
 . 4          {
 . 5              the System.Net.Mail.SmtpClient Client = new new the System.Net.Mail.SmtpClient ();
 . 6              client.Host = " smtp.163.com " ; // use the SMTP server 163 to send mail 
. 7              client.UseDefaultCredentials = to true ;
 . 8              client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
 . 9              // should be noted here that the user name is not filled with content behind @ , not the mailbox password login password, the mailbox is the authorization code
10             client.Credentials = new System.Net.NetworkCredential("zhangwy", "wy123456");
11 
12             System.Net.Mail.MailMessage Message = new System.Net.Mail.MailMessage();
13             Message.From = new System.Net.Mail.MailAddress("[email protected]");
14             Message.To.Add("[email protected]");
15             Message.Body = "测试邮件体";
16             Message.SubjectEncoding = System.Text.Encoding.UTF8;
17             Message.BodyEncoding = System.Text.Encoding.UTF8;
18             Message.Priority = System.Net.Mail.MailPriority.High;
19             Message.IsBodyHtml = true;
20             client.Send(Message);
21         }
22     }

 

Guess you like

Origin www.cnblogs.com/zhangjd/p/11221871.html