Asp. NET send E-mail

Source: Internet
Author: User
Tags mailmessage net send smtpclient
<span id="Label3"></p><p><p><span style="color: #993300;"><strong>1. Supplementary Knowledge</strong></span></p></p><p><p><strong>(1) what are POP3 and SMTP servers?</strong></p></p><p class="reply-text mb10"><p class="reply-text mb10">Simply Put: POP3 is used to receive e-mail, and SMTP is used to send E-mail.</p></p><p class="reply-text mb10"><p class="reply-text mb10"><strong>(1) What does POP3 specifically refer to?</strong></p></p><p class="reply-text mb10"><p class="reply-text mb10">POP3 (post Office Protocol 3) is the 3rd version of the Post Office protocol, which is a protocol that specifies how personal computers connect to mail servers on the Internet to send and receive Mail. It is the first offline protocol standard for Internet e-mail, and the POP3 protocol allows users to store messages from the server on a local host (that is, their own computer) while deleting or saving messages on the mail server based on the Client's actions, while the POP3 server is a receiving mail server that follows the POP3 Protocol. Used to receive E-mail. The POP3 protocol is a member of the TCP/IP protocol family, defined by RFC 1939</p></p><p class="reply-text mb10"><p class="reply-text mb10"><strong>(2) What does SMTP mean specifically?</strong></p></p><p class="reply-text mb10"><p class="reply-text mb10">The full name of SMTP is "simple mail Transfer Protocol", which is simply the message transfer Protocol. It is a set of specifications for transferring messages from the source address to the destination, which controls how messages are Relayed. The SMTP protocol is a TCP/IP protocol cluster that helps each computer find its next destination when sending or relaying Letters. The SMTP server is the outgoing mail server that follows the SMTP Protocol.</p></p><p class="reply-text mb10"><p class="reply-text mb10"></p></p><p class="reply-text mb10"><p class="reply-text mb10"><strong><span style="color: #993300;">2.system.net.mail</span></strong></p></p><p class="reply-text mb10"><p class="reply-text mb10">You need to reference the System.Net.Mail namespace to send e-mail using asp. <span class="selflink">the System.Net.Mail namespace contains classes that are used to send e-mail messages to a Simple Mail Transfer Protocol (SMTP) server for Delivery. </span></p></p><p class="reply-text mb10"><p class="reply-text mb10"><strong>(1) There are three more major classes under the Namespace:</strong></p></p><p class="reply-text mb10"><p class="reply-text mb10">Mailmessage: provides properties and methods to create a mail message object, which is the message Content.</p></p><p class="reply-text mb10"><p class="reply-text mb10">Attachment: provides properties and methods to create a message attachment object, which is a message attachment.</p></p><p class="reply-text mb10"><p class="reply-text mb10">Smtpclient: transfers the e-mail message to the SMTP host that you specified for mail delivery.</p></p><p class="reply-text mb10"><p class="reply-text mb10"><strong>(2) MailMessage class:</strong></p></p><p class="reply-text mb10"><p class="reply-text mb10">From: the address of the sending message<br>To: the address of the receiving message<br>Subject: the title of the message<br>Priority: messages are prioritized (for high,low,normal, respectively)<br>Attachments: an attachment collection of data for an e-mail message<br>Bcc: Secret delivery address<br>Cc: cc Address<br>Body: message body<br>Subjectencoding: the encoding used for the subject content of the e-mail</p></p><p class="reply-text mb10"><p class="reply-text mb10">Isbodyhtml: whether the message body is an Html-formatted value</p></p><p class="reply-text mb10"><p class="reply-text mb10">Detailed Reference: MailMessage<br></p></p><p class="reply-text mb10"><p class="reply-text mb10"><strong>(3) Attachment Class:</strong></p></p><p class="reply-text mb10"><p class="reply-text mb10">Detailed Reference: Attachment</p></p><p class="reply-text mb10"><p class="reply-text mb10"><strong>(4) SmtpClient class:</strong></p></p><p class="reply-text mb10"><p class="reply-text mb10">deliverymethod: Specifies how outgoing e-mail messages are processed</p></p><p class="reply-text mb10"><p class="reply-text mb10">The name or IP address of the host that host:smtp the transaction</p></p><p class="reply-text mb10"><p class="reply-text mb10">Credentials: set Credentials to verify sender identity</p></p><p class="reply-text mb10"><p class="reply-text mb10">Detailed Reference: SmtpClient</p></p><p class="reply-text mb10"><p class="reply-text mb10"></p></p><p class="reply-text mb10"><p class="reply-text mb10"><strong><span style="color: #993300;">3.ASP. Net send mail two ways</span></strong></p></p><p class="reply-text mb10"><p class="reply-text mb10"><strong>(1) sending mail via SMTP from the mail service provider</strong></p></p><p class="reply-text mb10"><p class="reply-text mb10">first, you need to register the corresponding service provider free mailbox, because you want to use the Mail service Provider's smtp, They need to authenticate the identity, so as to avoid the generation of large amounts of junk e-mail.</p></p><p class="reply-text mb10"><p class="reply-text mb10">There are three important messages: SMTP server, user name, Password. From the online collection of several classes, you can refer to the Next.</p></p><pre> <span style="color: #0000ff;"><span style="color: #0000ff;">#region</span></span><summary>//<span style="color: #000000;"><span style="color: #000000;">Send mail</span></span></summary>//<param name=<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">MailTo</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>> E-mail to be sent </param>//<param name=<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">Mailsubject</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>> Email Topics </param>//<param name=<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">mailcontent</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>> Mailbox Content </param>//<returns> return results of sending mailboxes </returns><span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">Static</span></span>BOOL SendEmail (<span style="color: #0000ff;"><span style="color: #0000ff;">string</span></span>mailTo,<span style="color: #0000ff;"><span style="color: #0000ff;">string</span></span>mailsubject,<span style="color: #0000ff;"><span style="color: #0000ff;">string</span></span><span style="color: #000000;"><span style="color: #000000;">Mailcontent) { </span></span>//<span style="color: #000000;"><span style="color: #000000;">set the Sender's mail information, such as using Netease's SMTP</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">string</span></span>SmtpServer =<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">smtp.163.com</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>; //<span style="color: #000000;"><span style="color: #000000;">SMTP Server</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">string</span></span>Mailfrom =<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">[email protected]</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>; //<span style="color: #000000;"><span style="color: #000000;">Login User Name</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">string</span></span>UserPassword =<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">XXX</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>;//<span style="color: #000000;"><span style="color: #000000;">Login Password</span></span>//<span style="color: #000000;"><span style="color: #000000;">Mail Service settings smtpclient smtpclient</span></span>=<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">SmtpClient (); Smtpclient.deliverymethod</span></span>= smtpdeliverymethod.network;//<span style="color: #000000;"><span style="color: #000000;">Specify how e-mail is sent Smtpclient.host</span></span>= smtpserver; //<span style="color: #000000;"><span style="color: #000000;">Specify the SMTP server Smtpclient.credentials</span></span>=<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span>System.Net.NetworkCredential (mailfrom, userpassword);//<span style="color: #000000;"><span style="color: #000000;">user name and password</span></span>//<span style="color: #000000;"><span style="color: #000000;">Send mail settings mailmessage mailmessage</span></span>=<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span>MailMessage (mailfrom, mailTo); //<span style="color: #000000;"><span style="color: #000000;">sender and Recipient Mailmessage.subject</span></span>= mailsubject;//<span style="color: #000000;"><span style="color: #000000;">Theme Mailmessage.body</span></span>= mailcontent;//<span style="color: #000000;"><span style="color: #000000;">content mailmessage.bodyencoding</span></span>= encoding.utf8;//<span style="color: #000000;"><span style="color: #000000;">Body Code mailmessage.isbodyhtml</span></span>=<span style="color: #0000ff;"><span style="color: #0000ff;">true</span></span>;//<span style="color: #000000;"><span style="color: #000000;">set to HTML format mailmessage.priority</span></span>= mailpriority.low;//<span style="color: #000000;"><span style="color: #000000;">Priority Level</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Try</span></span><span style="color: #000000;"><span style="color: #000000;">{smtpclient.send (mailmessage);</span></span>//<span style="color: #000000;"><span style="color: #000000;">Send mail</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">true</span></span><span style="color: #000000;"><span style="color: #000000;">; } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Catch</span></span><span style="color: #000000;"><span style="color: #000000;">(smtpexception Ex) {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">false</span></span><span style="color: #000000;"><span style="color: #000000;">; } }</span></span></pre><p><p><strong>(2) use SMTP of native SMTP virtual server to send mail</strong></p></p><p class="reply-text mb10"><p class="reply-text mb10">SMTP configuration is required, or the first is simple and practical.</p></p><p class="reply-text mb10"><p class="reply-text mb10"></p></p><p class="reply-text mb10"><p class="reply-text mb10"><span style="color: #993300;"><strong>4. reference: Common mail server</strong></span></p></p><p class="reply-text mb10"><p class="reply-text mb10">Gmail.com:<br>POP3 Server Address: pop.gmail.com<br>SMTP Server Address: smtp.gmail.com</p></p><p class="reply-text mb10"><p class="reply-text mb10">Qq.com:</p></p><p class="reply-text mb10"><p class="reply-text mb10">POP3 Server Address: pop.qq.com<br>SMTP Server Address: smtp.qq.com</p></p><p class="reply-text mb10"><p class="reply-text mb10">163.com:<br>POP3 Server Address: pop.163.com<br>SMTP Server Address: smtp.163.com</p></p><p class="reply-text mb10"><p class="reply-text mb10">Sina.com:<br></p></p><p class="reply-text mb10"><p class="reply-text mb10">POP3 Server Address: pop3.sina.com.cn<br>SMTP Server Address: smtp.sina.com.cn</p></p><p class="reply-text mb10"><p class="reply-text mb10">Yahoo.com:<br>POP3 Server Address: pop.mail.yahoo.com<br>SMTP Server Address: smtp.mail.yahoo.com</p></p><p class="reply-text mb10"><p class="reply-text mb10">Sohu.com:<br>POP3 Server Address: pop3.sohu.com<br>SMTP Server Address: smtp.sohu.com</p></p><p class="reply-text mb10"><p class="reply-text mb10">China.com:<br>POP3 Server Address: pop.china.com<br>SMTP Server Address: smtp.china.com</p></p><p class="reply-text mb10"><p class="reply-text mb10"><br>21cn.com:<br>POP3 Server Address: pop.21cn.com<br>SMTP Server Address: smtp.21cn.com sina.com:<br><br></p></p><p><p>Asp. NET send E-mail</p></p></span>

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.