ASP. NET send Message code System.Net.Mail

Source: Internet
Author: User
Tags mailmessage net send smtpclient

Front page sendemail.aspx Code

Using System.Net.Mail;
Using System.Net;

Send e-mail demo"0"cellspacing="0"Border="0"style="font-family: Song body, Arial, Helvetica, Sans-serif;font-size:15px; width:411px;"><tr> &LT;TDclass="Style5">e-mail address:</td> &LT;TDclass="Style6"> <asp:textbox id="Tb_email"runat="Server"Width="269px"></asp:TextBox> </td> </tr> <tr> <tdclass="Style5">cc to:</td> &LT;TDclass="Style6"> <asp:textbox id="TB_CC"runat="Server"Width="268px"></asp:TextBox> </td> </tr> <tr> <tdclass="Style5">Message Subject:</td> &LT;TDclass="Style6"> <asp:textbox id="Tb_subject"runat="Server"Width="268px"></asp:TextBox> </td> </tr> <tr> <tdclass="Style5">Message content:</td> &LT;TDclass="Style6"> <asp:textbox id="Tb_body"runat="Server"height="63px"Textmode="MultiLine"Width="266px"></asp:TextBox> </td> </tr> <tr> <tdclass="Style5">To add an attachment:</td> &LT;TDclass="Style6"> <asp:fileupload id="tb_attachment"runat="Server"Width="265px"/> </td> </tr> <tr> <td align=" Right"colspan="2"> <asp:button id="Btn_sendemail"runat="Server"text="Send mail"onclick="Btn_sendemail_click"/> </td> </tr> </table>

Background SendEmail.aspx.cs Code

protected voidBtn_sendemail_click (Objectsender, EventArgs e) {            //declaring a Mail objectMailMessage MyMail =NewMailMessage (); //Sender Address//as yourself, enter your own mailbox hereMyMail. from =NewMailAddress ("[email protected]"); //Recipient AddressMyMail. To.add (Newmailaddress (Tb_email.text)); //Message SubjectMyMail. Subject =Tb_subject.text; //Message Header encodingMyMail. Subjectencoding =System.Text.Encoding.UTF8; //Send the contents of a messageMyMail. Body =Tb_body.text; //Message content EncodingMyMail. Bodyencoding =System.Text.Encoding.UTF8; //Add an attachmentAttachment myfiles =NewAttachment (tb_Attachment.PostedFile.FileName); MyMail.            Attachments.Add (myfiles); //cc to another mailboxMyMail. Cc. ADD (Newmailaddress (tb_cc.            Text)); //whether it is an HTML messageMyMail. isbodyhtml =true; //Message PriorityMyMail. Priority =Mailpriority.high; //Create a mail server classSmtpClient myclient =NewSmtpClient (); MyClient. Host="smtp.163.com"; //SMTP Service PortMyClient. Port = -; //Verify LoginMyClient. Credentials =NewNetworkCredential ("@@@@@@","*****");//"@" Enter a valid message name, "*" Enter a valid passwordmyclient.        Send (MyMail); }

ASP. NET send Message code System.Net.Mail

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.