Detailed explanation of mass e-mail function realized by


This paper describes the mass e-mail function realized by ASP. Net. Share with you for your reference, as follows:

Some time ago, a group email function was needed in the website developed for teachers, and there were some problems with the group email function of we7 when I studied CMS system. So I went online to check the information, summarized it, and sealed it into a class. It is useful for personal testing and supports attachments. I hope it will be helpful to you, I used QQ email when testing. The prerequisite for success is to open the SMTP service function in the email setting. For example, check the required functions in the Account tab in QQ email setting:

The principle of other mailboxes is the same~~~~~~

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Web;
namespace MailSend
  public class SendEmail
    /// <summary>
    ///Mass mail function
    /// </summary>
    ///< param name = "subject" > sent topic < / param >
    ///< param name = "body" > content sent < / param >
    ///< param name = "email_list" > the recipient list can be separated by | and you can define < / param >
    ///< param name = "file_path" > the address to send the attachment. After obtaining the path, upload < / param >
    public static void Send(string subject, string body, string email_list, string File_Path)
      string MailUser = " [email protected] ";// I tested QQ mailbox, which is the same as other mailboxes
      String mailpwd = "your password"// Mailbox password
      String mailname = "test";
      string MailHost = "";// Query the SMTP address according to the mailbox you choose
      MailAddress from = new MailAddress(MailUser, MailName); // Sender of message
      MailMessage mail = new MailMessage();
      //Set the title of the message
      mail.Subject = subject;
      //Set the sender of the message
      //Pass: if you don't want to display your email address, you can fill in any name in the mail format. The real mail user is not set here. This is only for display
      mail.From = from;
      //Set the recipient of the message
      string address = "";
      //Multiple incoming mailboxes are separated by "|" and can be customized, and then added to the list through mail. To. Add()
      string[] email = email_list.Split('|');
      foreach (string name in email)
        if (name != string.Empty)
          address = name;
          mail.To.Add(new MailAddress(address));
      //Set CC recipients for messages
      //This is much simpler. If you don't want to be laid off quickly, it's better to give CC a copy of the important documents to the leaders
      //mail.CC.Add(new MailAddress(" [email protected] "," respected leader ");
      //Set the content of the message
      mail.Body = body;
      //Format messages
      mail.BodyEncoding = System.Text.Encoding.UTF8;
      mail.IsBodyHtml = true;
      //Set the sending level of the message
      mail.Priority = MailPriority.Normal;
      //Set email attachments, upload the attachments selected at the client to the server, save one, and then add it to the 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 used for SMTP transactions and fill in the IP address
      client.Host = MailHost;
      //Set the port for SMTP transactions. The default is 25
      client.Port = 25;
      client.UseDefaultCredentials = false;
      //Here is the real email login name and password. My user name is mailuser and my password is mailpwd
      client.Credentials = new System.Net.NetworkCredential(MailUser, MailPwd);
      client.DeliveryMethod = SmtpDeliveryMethod.Network;
      ////If the sending fails, the SMTP server will send a failed email to tell me
      mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
      //It's all defined and officially sent. It's very simple!

For more information about, readers who are interested can see the special topics on this site:《Summary of optimization skills》、《Summary of string operation skills》、《Summary of operating XML skills》、《Summary of file operation skills》、《 Ajax skills summary topic》And《Summary of cache operation skills》。

I hope this article will help you in ASP. Net programming.

Recommended Today

Beautify your code VB (VBS) code formatting implementation code

However, does have many new functions that VB6 does not have. The automatic typesetting of code is one, which is the function we want to realize today – VB code formatting.Let’s look at the effect: Before formatting: Copy codeThe code is as follows: For i = 0 To WebBrowser1.Document.All.length – 1 If WebBrowser1.Document.All(i).tagName = […]