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> <TDclass="Style5">e-mail address:</td> <TDclass="Style6"> <asp:textbox id="Tb_email"runat="Server"Width="269px"></asp:TextBox> </td> </tr> <tr> <tdclass="Style5">cc to:</td> <TDclass="Style6"> <asp:textbox id="TB_CC"runat="Server"Width="268px"></asp:TextBox> </td> </tr> <tr> <tdclass="Style5">Message Subject:</td> <TDclass="Style6"> <asp:textbox id="Tb_subject"runat="Server"Width="268px"></asp:TextBox> </td> </tr> <tr> <tdclass="Style5">Message content:</td> <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> <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