First, add a namespaceusingSystem.Net.Mail; /// <summary> ///Send mail/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> protected voidFormail (stringNamestringMail) { Try { //string email = txtemail. Text.trim ();MailAddress Messagefrom =NewMailAddress (""Outbox Address"");//Sender e-mail address stringmessageto = mail;//Recipient Email Address stringMessageSubject = BS. HtmlEncode (Web_zt. Value.trim ());//Message Subject stringMessageBody =""+ Content1. Value.trim () +"";//message content (usually a URL link, generate random number plus verification ID parameters, click to go to site verification. ) "; if(Send (Messagefrom, Messageto, MessageSubject, MessageBody)) {//Response.Write ("Send mail Success"); } Else { //Response.Write ("Failed to send mail"); } } Catch { //Clientscript.registerstartupscript (Clientscript.gettype (), "MyScript", "<script>alert (' Customer information deletion failed ') </ Script> "); } } /// <summary> ///send e-mail/// </summary> /// <param name= "Messagefrom" >Sender e-mail address</param> /// <param name= "Messageto" >Recipient Email Address</param> /// <param name= "MessageSubject" >Message Subject</param> /// <param name= "MessageBody" >Message Content</param> /// <returns></returns> Public BOOLSend (MailAddress Messagefrom,stringMessageto,stringMessageSubject,stringmessagebody) {MailMessage message=NewMailMessage (); Message. from=Messagefrom; Message. To.add (Messageto); //The recipient email address can be multiple to achieve massMessage. Subject =MessageSubject; Message. Body=MessageBody; Message. Isbodyhtml=true;//is HTML formatMessage. priority = Mailpriority.normal;//priority level for sending messagesSmtpClient sc =NewSmtpClient (); Sc. Host="smtp.qq.com";//Specify the server address or IP to send mail toSc. Port = -;//Specify the Send mail portSc. Credentials =NewSystem.Net.NetworkCredential (""Outbox Address"",""Outbox Password"");//Specify the user name and password of the login server (sender's mailbox login password) Try{SC. Send (message); //Send mail } Catch { return false; } return true; }
ASP. NET Send mail