Example: Use net. mail of c #. net to send an email (simple and practical)
1 SmtpClient smtpClient = new SmtpClient ();
2 smtpClient. DeliveryMethod = SmtpDeliveryMethod. Network; // specify the email sending Method
3 smtpClient. Host = "smtp.sohu.com"; // specify the SMTP server
4 smtpClient. Credentials = new System. Net. NetworkCredential ("xxx", "yyy"); // user name and password
5
6
7 String body = "Test ";
8
9
10 MailMessage mailMessage = new MailMessage ("xxx@sohu.com", "297680@qq.com ");
11 mailMessage. Subject = "Hello"; // Subject
12 mailMessage. Body = body; // content
13 mailMessage. BodyEncoding = System. Text. Encoding. UTF8; // body Encoding
14 mailMessage. IsBodyHtml = true; // set it to HTML Format
15 mailMessage. Priority = MailPriority. High; // Priority
16
17 try
18 {
19 smtpClient. Send (mailMessage );
20 return true;
21}
22 catch
23 {
24 return false;
25}
Note: reference a namespace
Using System. Net. Mail;