ASP. e-mail sent using QQ mailbox

Source: Internet
Author: User
Tags mailmessage smtpclient

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Net;usingSystem.Net.Mail;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;namespacewebapplication1{ Public Partial classCemail:System.Web.UI.Page {Private stringSfrom ="[email protected]";//Sender e-mail        Private stringSfromer ="Sending Person"; Private stringStoer ="Recipient"; Private stringSsmtphost ="smtp.qq.com";//SMTP Server        Private stringSsmtpuser ="[email protected]";//User Login name        Private stringSsmtppass ="Authorization Code";//Login Password-The new version of the QQ mailbox is the use of authorization code, need to mailbox-Setup-account inside Find-Generate authorization code-copy in;        protected voidPage_Load (Objectsender, EventArgs e) {        }        protected voidBtnsend_click (Objectsender, EventArgs e) {            stringSTO =TxtSto.Text.Trim (); stringCC =TxtCC.Text.Trim (); stringtitle =TxtTitle.Text.Trim (); stringContent =TxtContent.Text.Trim (); if(string. IsNullOrEmpty (STO) | |string. IsNullOrEmpty (title) | |string. IsNullOrEmpty (content)) {Response.Write ("<script>alert (' recipient, title, content cannot be empty ') </script>"); }            Else{mailaddress from=NewMailAddress (Sfrom, Sfromer);//Sender Address ObjectMailAddress to =NewMailAddress (sto, stoer);//Recipient Address ObjectMailMessage Omail =NewMailMessage ( from, to); Omail.subject= title;//set the message headerOmail.body = content;//Set Message text contentomail.isbodyhtml =false;//set to HTML formatomail.bodyencoding = System.Text.Encoding.GetEncoding ("GB2312");//Body Codeomail.priority = Mailpriority.high;//Priority Level                if(CC! ="")                {                    if(CC. ToLower (). IndexOf (';') >0) {cc= CC. Substring (0Cc. Length-1); string[] acc = cc. Split (';'); foreach(varCinchACC)                        {OMAIL.CC.ADD (c); }                    }                    Else{oMail.CC.Add (CC); }} SmtpClient Client=NewSmtpClient (); Client. Enablessl=true;//This property must be set to True because the authorization code is usedClient. Host = Ssmtphost;//Specify the SMTP serverClient. Credentials =NewNetworkCredential (Ssmtpuser, Ssmtppass);//the user name and password of the mailbox, note that the password using the QQ mailbox is the authorization codeClient. Deliverymethod = Smtpdeliverymethod.network;//specify how e-mail is sent                Try{client.                    Send (Omail); Response.Write ("<script>alert (' send Success ') </script>"); }                Catch{Response.Write ("<script>alert (' send failed ') </script>"); }                finally{omail.dispose (); }            }                   }    }}
<%@ Page language="C #"autoeventwireup="true"Codebehind="Cemail.aspx.cs"inherits="Webapplication1.cemail"%><! DOCTYPE html>"http://www.w3.org/1999/xhtml">"Server"> <meta http-equiv="Content-type"Content="text/html; Charset=utf-8"/> <title></title>"Form1"runat="Server"> <div> <table> <tr> <td> recipient Email </td> <td> <asp:textbox id="Txtsto"runat="Server"></asp:TextBox></td> </tr> <tr> <td> cc &L t;/td> <td> <asp:textbox id="TXTCC"runat="Server"></asp:TextBox> </td> </tr> <tr> <td> title </td> <td> <asp:textbox id="Txttitle"runat="Server"></asp:TextBox></td> </tr> <tr> <td> content &L t;/td> <td> <asp:textbox id="txtcontent"runat="Server"height="136px"Textmode="MultiLine"Width="254px"></asp:TextBox></td> </tr> <tr> <td> <asp:button id="Button1"runat="Server"text=" Reset"/></td> <td> <asp:button id="Btnsend"runat="Server"text="Submit"onclick="Btnsend_click"/></td> </tr> </table> </div> </form></body>&lt ;/html>

QQ Mailbox Setup Tutorial

----Here is OK, in fact, the main and like Sohu e-mail message is different

One: Set SmtpClient's Enablessl property to true in code

Second: Set up the POP3/SMTP service in the QQ mailbox account, the other password is to use the authorization code

ASP. e-mail sent using QQ mailbox

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.