ASP. NET sends email

Source: Internet
Author: User
Tags mailmessage net send smtpclient

1. Additional knowledge

(1) What are POP3 and SMTP servers?

To put it simply, POP3 is used to receive emails, and SMTP is used to send emails.

(1) What does POP3 mean?

POP3 (Post Office Protocol 3) is the 3rd version of the Post Office Protocol. It specifies how a personal computer connects to the mail server on the Internet to send and receive mail. It is the first offline protocol standard for Internet email. POP3 allows you to store emails on a server to a local host (your computer, at the same time, emails are deleted or saved on the mail server according to client operations, while the POP3 server is a mail server that follows the POP3 protocol to receive emails. POP3 is a member of the TCP/IP protocol family, defined by RFC 1939.

(2) What does SMTP mean?

SMTP is short for "Simple Mail Transfer Protocol", that is, Simple Mail transmission protocol. It is a set of specifications used to transmit mails from the source address to the destination address. It is used to control the transfer mode of mails. The SMTP protocol is a TCP/IP protocol cluster that helps each computer locate the next destination when sending or transferring letters. The SMTP server is the mail sending server that follows the SMTP protocol.

 

2. system. net. Mail

To send an email using ASP. NET, you must reference the system. net. Mail namespace.System. net. MailThe namespace contains classes used to send emails to Simple Mail Transfer Protocol (SMTP) servers for transmission.

(1) There are three main classes in the namespace:

Mailmessage: Provides attributes and methods to create a mail message object, that is, the Mail content.

Attachment: Provides attributes and methods to create an email attachment object, that is, an email attachment.

Smtpclient: transfers an email to the SMTP host you specified for mail delivery.

(2) mailmessage class:

From: email sending Address
To: email Receiving address
Subject: Mail title
Priority: Mail priority (high, low, normal)
Attachments: a collection of attachments to email data
BCC: BCC address
Cc: CC address
Body: Body of the email
Subjectencoding: encoding used for the subject content of the email

Isbodyhtml: whether the email body is in HTML Format

For details, refer to mailmessage.

(3) Attachment class:

For details, refer to Attachment.

(4) smtpclient class:

Deliverymethod: Specifies how to process emails to be sent.

HOST: Name or IP address of the SMTP transaction host

Credentials: sets credentials for Sender authentication.

For details, see smtpclient.

 

3. ASP. NET send mail in two ways

(1) send emails through SMTP of the mail service provider

First, you need to register a free email address for the corresponding service provider. Because you want to use the SMTP address of the mail service provider, they need to verify their identity so as to avoid a large amount of spam.

There are three important information: SMTP server, user name, and password. Several Classes are collected from the Internet. For more information, see.

 

     # Region      ///   <Summary>      ///  Send email  ///   </Summary>      ///   <Param name = "mailto">  Email address to be sent  </Param>      ///   <Param name = "mailsubject"> Email Subject  </Param>      ///   <Param name = "mailcontent">  Email content  </Param>      ///   <Returns>  Return the email sending result.  </Returns>      Public   Static   Bool Sendemail ( String Mailto, String Mailsubject,String  Mailcontent ){  //  Set the sender's mail information, for example, using Netease's SMTP          String Smtpserver = "  Smtp.163.com  " ; //  SMTP Server          String Mailfrom = "  XXX@163.com  " ; // Login Username          String Userpassword = "  Xxx  " ; //  Login Password  //  Email service settings Smtpclient = New  Smtpclient (); smtpclient. deliverymethod = Smtpdeliverymethod. Network; //  Specify email sending Method Smtpclient. Host = smtpserver;//  SMTP Server Smtpclient. Credentials = New System. net. networkcredential (mailfrom, userpassword ); //  Username and password  //  Email sending settings Mailmessage = New Mailmessage (mailfrom, mailto ); //  Sender and recipient Mailmessage. Subject = mailsubject; //  Topic Mailmessage. Body = mailcontent;//  Content Mailmessage. bodyencoding = encoding. utf8; //  Body code Mailmessage. isbodyhtml = True ; //  Set to HTML Format Mailmessage. Priority = mailpriority. low; //  Priority          Try  {Smtpclient. Send (mailmessage );  //  Send email             Return   True  ;}  Catch  (Smtpexception ex ){  Return   False  ;}} 

 

(2) Use the SMTP of the local SMTP virtual server to send emails

SMTP configuration is the first simple and practical method.

 

4. References: common email servers

Gmail.com:
POP3 server address: pop.gmail.com
SMTP server address: smtp.gmail.com

QQ.com:

POP3 server address: pop.qq.com
SMTP server address: smtp.qq.com

163. com:
POP3 server address: pop.163.com
SMTP server address: smtp.163.com

Sina.com:

POP3 server address: pop3.sina.com.cn
SMTP server address: smtp.sina.com.cn

Yahoo.com:
POP3 server address: pop.mail.yahoo.com
SMTP server address: smtp.mail.yahoo.com

Sohu.com:
POP3 server address: pop3.sohu.com
SMTP server address: smtp.sohu.com

China.com:
POP3 server address: pop.china.com
SMTP server address: smtp.china.com

21cn.com:
POP3 server address: pop.21cn.com
SMTP server address: smtp.21cn.com Sina.com:

Download instance

 

Author: forevernome
Source: http://www.cnblogs.com/ForEvErNoME/
You are welcome to repost or share it, but be sure to declare it Article Source. If the article is helpful to you, I hope you can Recommendation Or Follow

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.