C # Send mail

Source: Internet
Author: User
Tags mail code mailmessage smtpclient

Today, the following C # e-mail code, mainly refer to others, the original: http://www.cnblogs.com/xuchi/archive/2011/12/15/2288663.html

1        /// <summary>2         ///Send mail3         /// </summary>4         /// <param name= "SMTP" >Outgoing Server</param>5         /// <param name= "pwd" >Sender Password</param>6         /// <param name= "SendMail" >Sender Mailbox</param>7         /// <param name= "Recipientmail" >Recipient Mailbox</param>8         /// <param name= "Sendusername" >Sender's name</param>9         /// <param name= "Recipientusername" >Recipient's name</param>Ten         /// <param name= "Subject" >Message Subject</param> One         /// <param name= "Body" >Message Content</param> A         /// <param name= "CC" >cc Person</param> -         /// <returns>whether the send was successful</returns> -          Public Static stringSendMail (stringSmtpstringPwdstringSendMail,stringRecipientmail,stringSendusername,stringRecipientusername,stringSubject,stringBody,string[] CC) the         { -             Try -             { -SmtpClient client =NewSmtpClient (SMTP);//Initializing the server +  -Client. useDefaultCredentials =false; +Client. Credentials =NewNetworkCredential (SendMail, PWD);//Sender's account, password AClient. Deliverymethod = Smtpdeliverymethod.network;//Specify how outgoing messages are processed at  -MailAddress Addressfrom =NewMailAddress (SendMail, sendusername);//Sender address, name -MailAddress Addressto =NewMailAddress (Recipientmail, recipientusername);//recipient address, name -  -                 //Attachment att= New Attachment (""); //Accessories -  inMailMessage message =NewMailMessage (Addressfrom, Addressto);//Sending -                 //looping through cc people to                 foreach(varIteminchCC) +                 { - message. Cc. ADD (item); the                 }                 *  $Message. Sender =NewMailAddress (SendMail);//Sender AddressPanax NotoginsengMessage. Subject = Subject;//Theme -Message. BODY = body;//content theMessage. bodyencoding = Encoding.UTF8;//Coding +Message. isbodyhtml =true;//is HTML format A  the client. Send (message); +                 return "true"; -             } $             Catch(Exception ex) $             { -                 return(ex. Message); -             } the}

C # Send mail

Related Article

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.