This article mainly introduces the bulk e-mail function of ASP, and analyzes the related operation skill and attention matters of ASP. e-mail based on the SMTP service, and the need of friends can refer to the following
The example in this article describes the bulk mail functionality implemented by ASP. Share to everyone for your reference, as follows:
Some time ago in the development of the teacher to help the site need to use a mass mailing function, and their own before learning CMS system with the We7 mass mail function also have some problems, so he went online to check the information, summed up a bit, and encapsulated into a class, pro-Test useful, support accessories, Hope that we also have some help, I test with QQ mailbox, the premise of success is to open the SMTP service in the mailbox settings, such as the QQ mailbox settings inside the Account tab inside the required functions on the hook:
Other mailboxes the same principle ~~~~~~
Using system;using system.collections.generic;using system.linq;using system.net.mail;using System.Web;namespace mailsend{public class SendEmail {//<summary>///bulk Mail function//</summary>//<param name= "s Ubject "> Topics sent </param>//<param name=" Body "> Content to be sent </param>//<param name=" Email_list "> Received A list of items, separated by |, can be defined by themselves </param>///<param Name= "File_path" > Send attachment Address, get path after upload </param> public static VO ID Send (string subject, String body, String email_list, String file_path) {string mailuser = "XXX@qq.com";//I'm testing QQ Mailbox, other mailbox the same reason string mailpwd = "Your password";//mailbox password string mailname = "Test"; String MailHost = "smtp.exmail.qq.com";//The address of SMTP is queried according to the mailbox of your choice mailaddress from = new MailAddress (Mailuser, mailname); The sender of the message mailmessage mail = new MailMessage (); Set the title of the message mail. Subject = Subject; Set the sender of the message//pass: If you do not want to display their e-mail address, here can fill in the mail format of any name, the real mail user is not set here, this is only to do the display with MaiL.from = from; Set the recipient of the message to string address = ""; Pass in multiple mailboxes with the ' | ' Split open, you can customize, and then through mail. To.add () Add to list string[] email = email_list. Split (' | '); foreach (string name in email) {if (name! = string. Empty) {address = name; Mail. To.add (address) (new mailaddress); }}//Set CC recipients for the message//This is much simpler, if you do not want to quickly laid off important documents or cc a copy to the leadership better//mail. Cc. ADD (New MailAddress ("Manage@hotmail.com", "honorable Leader"); Set the contents of the message mail. BODY = body; Format the message in mail. bodyencoding = System.Text.Encoding.UTF8; Mail. Isbodyhtml = true; Set the Send level mail for the message. priority = Mailpriority.normal; Set the attachment of the message, upload the attachment selected by the client to the server to save one, and then add it to mail if (file_path! = "") {mail. Attachments.Add (New Attachment (File_path)); Mail. Deliverynotificationoptions = deliverynotificationoptions.onsuccess; } smtpclient client = new SmtpClient (); Set the name of the host for the SMTP transaction, and the IP address can be the client. Host = MailHost; Set the end for SMTP transactionsPort, the default is the client. Port = 25; Client. useDefaultCredentials = false; Here is the real mailbox login name and password, my user name is Mailuser, my password is mailpwd client. Credentials = new System.Net.NetworkCredential (Mailuser, mailpwd); Client. Deliverymethod = Smtpdeliverymethod.network; If the send fails, the SMTP server sends a failed message to tell me mail. Deliverynotificationoptions = deliverynotificationoptions.onfailure; All defined, formally sent, it is simple! Client. Send (mail); } }}