Gadgets: email sending; tools: email sending

Source: Internet
Author: User
Tags mailmessage smtpclient

Gadgets: email sending; tools: email sending

I. Preparations

1. To write an email sending tool, you must first understand the following:

  • Recipient: The recipient of the email, the recipient of the email.
  • Cc: the recipient of the email. the sender of the email wants to know the content of the email.
  • BCC: the only difference between the recipient and the CC is that it makes it impossible for each recipient to see who the email is sent at the same time.
  • Email Subject: Brief description of the email content.
  • Text Content: The main content of the email.
  • Attachment: a file that is attached with an email and sent to the recipient's mailbox.
  • Sender: the sender of the email.

2. Prepare an email address. We have to make some settings for the mailbox.

The distance between 163 mailboxes is used this time. Because the smtp protocol is used, make sure that the smtp service of this mailbox is enabled. For more information, see http://help.163.com/09/1223/14/5r7p6cj600753vb8.html.

3. In addition, we need to activate a client Authorization password:

Our preparations have come to an end.

 

2. write code

1. initialize a mail class and assign values accordingly.

1 /// <summary> 2 // email information 3 /// </summary> 4 /// <returns> </returns> 5 private System. net. mail. mailMessage MailInfo () 6 {7 System. net. mail. mailMessage message = new System. net. mail. mailMessage (); 8 // recipient 9 message. to. add ("xxxxxx@qq.com"); 10 // CC 11 message. CC. add ("xxxxxxx@qq.com"); 12 // bcc cc 13 message. bcc. add ("xxxxxxxx@qq.com"); 14 message. subject = "Email Subject"; 15 message. body = "here is the Body of the email"; 16 message. bodyEncoding = Encoding. UTF8; 17 message. attachments. add (new System. net. mail. attachment ("Attachment .txt"); 18 // priority 19 message. priority = System. net. mail. mailPriority. high; 20 // sender 21 message. from = new System. net. mail. mailAddress ("xxxxxxxx@qq.com"); 22 return message; 23}

2. send an email

1 /// <summary> 2 /// send email 3 /// </summary> 4 private void SmtpSend () 5 {6 System. net. mail. smtpClient client = new System. net. mail. smtpClient (); 7 client. host = "smtp.163.com"; 8 client. port = 25; 9 client. credentials = new System. net. networkCredential ("xxxxxxxx@qq.com", "password"); 10 client. enableSsl = true; 11 client. deliveryFormat = System. net. mail. smtpDeliveryFormat. sevenBit; 12 client. deliveryMethod = System. net. mail. smtpDeliveryMethod. network; 13 client. send (MailInfo (); 14}

Iii. Running of semi-finished products

 

 

 

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.