C # send an email (for example, QQ or gmail)

Source: Internet
Author: User
Tags mail example email account mailmessage smtpclient
The email account and password used below are not authentic. If you need to test the password, replace it with your own email account. Need to reference: using system. net. mail; using system. text; using system. net; program code: mailmessage mymail = new mailmessage (); // create the mail Instance Object mymail. from = new mailaddress (""); // sender, which corresponds to the verification information of the email server and cannot be changed at will. to. add (New mailaddress (""); // recipient mymail. subject = "C # Send email"; // mail subject mymail. subjectencoding = encoding. utf8; // The title code is mymail. body = "this is a test email! "; // Mail content mymail. bodyencoding = encoding. utf8; // The email Content Encoding mymail. isbodyhtml = true; // whether the mail content supports HTML smtpclient SMTP = new smtpclient (); // create an SMTP Instance Object SMTP. host = "mail.sina.com"; // SMTP on the mail server. port = 25; // the mail server port SMTP. credentials = new networkcredential ("", "123456"); // SMTP. send (mymail); // mail example mailmessage mymail = new mailmessage (); mymail. from = new mailaddress (""); Myma Il. to. add (New mailaddress (""); mymail. subject = "C # Send email"; mymail. subjectencoding = encoding. utf8; mymail. body = "this is a test email from Gmail! <A href = 'HTTP: // www.sina.com.cn '> Sina </a> "; mymail. bodyencoding = encoding. utf8; mymail. isbodyhtml = true; smtpclient SMTP = new smtpclient (); SMTP. host = "smtp.gmail.com"; SMTP. port = 587; // SMTP port of Gmail SMTP. credentials = new networkcredential ("", "123456"); SMTP. enablessl = true; // Gmail requires SSL to connect to SMTP. deliverymethod = smtpdeliverymethod. network; // The Gmail sending method is through the network. You must specify SMTP. send (mymail); use QQ mail to send Mail example mailmessage mymail = new mailmessage (); mymail. from = new mailaddress (""); mymail. to. add (New mailaddress (""); mymail. subject = "C # Send email"; mymail. subjectencoding = encoding. utf8; mymail. body = "this is a test email from QQ! "; Mymail. bodyencoding = encoding. utf8; mymail. isbodyhtml = true; smtpclient SMTP = new smtpclient (); SMTP. host = "smtp.qq.com"; SMTP. credentials = new networkcredential ("", "123456"); SMTP. send (mymail );
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.