C # implements Mail generation

Source: Internet
Author: User
Tags mailmessage smtpclient

Because I am curious, there are some promotions and other mail, after the sender, there is a .... Hair generation.

Therefore, some data were found to verify the implementation.

Let's take a look at it and realize the ideal of generation.

  

Of course, this kind of, is the use of the sending mailbox server to send, (below you code, notes)

The code is as follows:

 //instantiate two necessaryMailMessage mail =NewMailMessage (); SmtpClient SMTP=NewSmtpClient (); //send e-mail addressMail. from =NewMailAddress ("[email protected]"); //here is the e-mail, the following Mailbox server address, but also fill out the server address of the sending mailboxMail. Sender =NewMailAddress ("[email protected]"); //recipients (can be mass)Mail. To.add (NewMailAddress ("[email protected]")); //whether to send in HTML formatMail. isbodyhtml =true; //encoding format for themesMail. Subjectencoding =Encoding.UTF8; //the title of the messageMail. Subject ="test the title of a issued piece"; //encoding format for contentMail. Bodyencoding =Encoding.UTF8; //priority of the messageMail. Priority =Mailpriority.normal; //send content, we feel free to fill in some. Mail. Body =@"Gets the user IP that opens the message, and the image is automatically generated by the server:"; //the recipient can be inside the messageMail. Headers.add ("disposition-notification-to","Receipt Information"); //the server address of the outgoing mailboxSmtp. Host ="smtp.163.com"; Smtp. Deliverymethod=smtpdeliverymethod.network; Smtp. Timeout=1000000; //is SSL encryptedSmtp. Enablessl =true; //set the port, if not set, the default port isSmtp. Port = -; Smtp. useDefaultCredentials=false; //verifying the sender's credentialsSmtp. Credentials =NewSystem.Net.NetworkCredential ("[email protected]","xxxx"); Try            {                //Send mailSMTP.                Send (mail); Console.WriteLine ("sent successfully"); }            Catch(Exception e) {Console.WriteLine ("Send failed:"+e.message); }

Of course, some of the above mailbox information, I changed some of the province, which sister, send me an e-mail Hahahahahahahahah

Let's look at the effect of the final implementation.

In this case, a generation of e-mail, successfully completed.

Note: The key to the code is

Mail. Sender = new MailAddress ("[email protected]");

The server address of the outgoing mailbox
Smtp. Host = "smtp.163.com";

C # implements Mail generation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.