A c # mail module, EmailHelper. the cs code is copied from a C # Toolkit, in ASP. NET or C # project, this class is very convenient, you can specify the mail title, mail body, recipient, HTML format and other parameters, the Code is as follows:
01 using System;
02 using System. Collections. Generic;
03 using System. Linq;
04 using System. Text;
05 namespace CLB. Utility. Tools
06 {
07 public class EmailHelper
08 {
09 // <summary>
10 // send an email
11 /// <summary>
12 /// <param name = "subject"> email title </param>
13 /// <param name = "body"> email body </param>
14 /// <param name = "to"> recipient </param>
15 /// <param name = "Ishtml"> whether it is in html format </param>
16 public static bool sendmail (string subject, string body, string to, bool Ishtml)
17 {
18 using (System. Net. Mail. MailMessage msg = new System. Net. Mail. MailMessage ())
19 {
20 msg. To. Add ();
21 msg. From = new System. Net. Mail. MailAddress ("email address", "title", System. Text. Encoding. UTF8 );
22 msg. Subject = subject; // mail title
23 msg. SubjectEncoding = System. Text. Encoding. UTF8; // email title Encoding
24 msg. Body = body; // mail content
25 msg. BodyEncoding = System. Text. Encoding. UTF8; // email Content Encoding
26 msg. IsBodyHtml = Ishtml; // whether it is an HTML email
27 msg. Priority = System. Net. Mail. MailPriority. High; // Mail Priority
28 System. Net. Mail. SmtpClient client = new System. Net. Mail. SmtpClient ();
29 client. Credentials = new System. Net. NetworkCredential ("email address", "password ");
30 client. Host = "Domain Name ";
31 object userState = msg;
32 try
33 {
34 client. Send (msg );
35 return true;
36}
37 catch
38 {
39 return false;
40}
41}
42}
43}
44}