C #. net email sending

Source: Internet
Author: User
Tags mailmessage smtpclient

Example: Use net. mail of c #. net to send an email (simple and practical)

 

 

1 SmtpClient smtpClient = new SmtpClient ();
2 smtpClient. DeliveryMethod = SmtpDeliveryMethod. Network; // specify the email sending Method
3 smtpClient. Host = "smtp.sohu.com"; // specify the SMTP server
4 smtpClient. Credentials = new System. Net. NetworkCredential ("xxx", "yyy"); // user name and password
5
6
7 String body = "Test ";
8
9
10 MailMessage mailMessage = new MailMessage ("xxx@sohu.com", "297680@qq.com ");
11 mailMessage. Subject = "Hello"; // Subject
12 mailMessage. Body = body; // content
13 mailMessage. BodyEncoding = System. Text. Encoding. UTF8; // body Encoding
14 mailMessage. IsBodyHtml = true; // set it to HTML Format
15 mailMessage. Priority = MailPriority. High; // Priority
16
17 try
18 {
19 smtpClient. Send (mailMessage );
20 return true;
21}
22 catch
23 {
24 return false;
25}

 

 

 

Note: reference a namespace

Using System. Net. 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.