A C # send mail module, EmailHelper.cs code, is copied from a C # toolkit, in asp.net or C # project to add send mail function, this class is very convenient, when used to specify the message title, message body, recipient, HTML format and other parameters can be, The code is as follows:
01using System;
02using System.Collections.Generic;
03using System.Linq;
04using System.Text;
05namespace CLB. Utility.tools
269
Modified public class Emailhelper
08 {
///<summary>
10///Send mail
One///<summary>
///<param name= "Subject" > Message title </param>
/// <param name= "Body" > message main </param>
/// <param name= "to" > recipient </param>
/// <param name= "ishtml" > is HTML format </param>
public static bool SendMail (string subject, string body, string to, bool ishtml)
17 {
using (System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage ())
19 {
Msg. To.add (to);
Msg. from = new System.Net.Mail.MailAddress ("email address", "title", System.Text.Encoding.UTF8);
Msg. Subject = subject;//message Header
Msg. subjectencoding = system.text.encoding.utf8;//message header encoding
Msg. BODY = body;//message Content
Msg. bodyencoding = system.text.encoding.utf8;//message content encoding
Msg. isbodyhtml = ishtml;//is an HTML message
Msg. Priority = system.net.mail.mailpriority.high;//Message priority
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient ();
Client. Credentials = new System.Net.NetworkCredential ("email address", "password");
Client. Host = "domain name";
Object userState = msg;
Try
33 {
Client. Send (msg);
return true;
36}
Panax Notoginseng Catch
38 {
return false;
40}
41}
42}
43}
44}