Send mail using System.Net.Mail

Source: Internet
Author: User
Tags mailmessage smtpclient

Reference namespaces:
Using System.Net.Mail;
<summary>
Send HTML mail with cc and BCC
Need to be configured in the Mailsettings node under System.Net in the Web. config file
</summary>
<param name= "mailto" > Recipient address </param>
<param name= "MAILCC" > CC address </param>
<param name= "MAILBCC" > Secret delivery address </param>
<param name= "Mailsubject" > Email subject </param>
<param name= "Mailbody" > Message body </param>
public static void SendMail (String mailto, string mailcc, String mailbcc, String mailsubject, String mailbody)
{
    MailMessage mmessage = new MailMessage ();
    MailAddress mTo = new MailAddress (mailto);
    if (MAILCC! = "") {mailaddress MCC = new MailAddress (MAILCC); MMESSAGE.CC.ADD (MCC); }
    if (mailbcc! = "") {mailaddress mbcc = new MailAddress (MAILBCC); MMESSAGE.BCC.ADD (MBCC); }
    MMESSAGE.TO.ADD (MTo);
    Mmessage.subject = Mailsubject;
    The character encoding for both the body and the subject is set to UTF8
    mmessage.subjectencoding = System.Text.Encoding.UTF8;
    mmessage.bodyencoding = System.Text.Encoding.UTF8;
    Mmessage.body = Mailbody;
    Text supports HTML
    Mmessage.isbodyhtml = true;
    SmtpClient client = new SmtpClient ();
    Client. Send (Mmessage);
}

Call:
SendMail ("[Email protected]", "", "", "TestData", "

Send mail using 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.