ASP. NET Send mail

Source: Internet
Author: User
Tags mailmessage net send smtpclient

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

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.