C # Send mail code

Source: Internet
Author: User

<summary>
Send e-mail
</summary>
<param name= "smtpserver" >SMTP server </param>
<param name= "UserName" > Login account </param>
<param name= "pwd" > Login password </param>
<param name= "nickname" > Sender nickname </param>
<param name= "Strfrom" > Sender </param>
<param name= "Strto" > Recipients </param>
<param name= "subj" > Themes </param>
<param name= "Bodys" > Content </param>
public static void SendMail (String smtpserver, String userName, string pwd, string nickname, String strfrom, String Strto, String subj, string bodys, int port)
{

MailMessage msg = new MailMessage ();
Msg. To.add (Strto);//Recipient address
Msg. Cc. Add ("[email protected]");//CC person address

Msg. from = new MailAddress (strfrom, nickname);//sender's mailbox, name
Msg. Subject = subj;//message Header
Msg. subjectencoding = encoding.utf8;//Header format is UTF8
Msg. Body =bodys;//Mail Content
Msg. bodyencoding = encoding.utf8;//content format is UTF8
Msg. Isbodyhtml = true; ;//set to HTML format

SmtpClient client = new SmtpClient ();
Client. Host = SMTPSERVER;//SMTP server address
Client. Port = port;//smtp, QQ mailbox Fill 587
Client. Enablessl = true;//Enable SSL encryption
Client. Credentials = new NetworkCredential (UserName, PWD);//Sender email account, password
Client. Send (msg);//E-mail
}

STMP Server: * SMTP server address for sending mail
SMTP port:

C # Send mail code

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.