"Go" C # send an email message

Source: Internet
Author: User
Tags email account mail account mailmessage smtpclient ssl connection

Transferred from: HTTP://HI.BAIDU.COM/BLUESKY_CN/ITEM/8BB060ACE834C53F020A4DF2

The e-mail account and password used below are not real and need to be tested and replaced by your email account.

References are required:

1 using System.Net.Mail; 2 using System.Text; 3 using System.Net;

Program code:

1MailMessage MyMail =NewMailMessage ();//Create a message instance object2Mymail.from =NewMailAddress ("");//sender, to the mail server verification information corresponding, can not be arbitrarily changed3         4MYMAIL.TO.ADD (NewMailAddress (""));//Recipient5Mymail.subject ="C # Send email";//message Header6mymail.subjectencoding = Encoding.UTF8;//Title Encoding7Mymail.body ="This is a test email!";//Message Content8mymail.bodyencoding = Encoding.UTF8;//Message content Encoding9mymail.isbodyhtml =true;//whether the message content supports HTMLTenSmtpClient SMTP =NewSmtpClient ();//To create an SMTP instance object OneSmtp. Host ="mail.sina.com";//Mail Server SMTP ASmtp. Port = -;//Mail server Port -Smtp. Credentials =NewNetworkCredential ("","123456");//Mail server Authentication information -Smtp. Send (MyMail);//Send mail

Example of sending a message using a Gmail mailbox

1MailMessage MyMail =NewMailMessage ();2Mymail.from =NewMailAddress ("");3MYMAIL.TO.ADD (NewMailAddress (""));4Mymail.subject ="C # Send email";5Mymail.subjectencoding =Encoding.UTF8;6Mymail.body ="This was a test email from gmail!<a href= ' http://www.sina.com.cn ' >sina</a>";7Mymail.bodyencoding =Encoding.UTF8;8mymail.isbodyhtml =true;9SmtpClient SMTP =Newsmtpclient ();TenSmtp. Host ="smtp.gmail.com"; OneSmtp. Port =587;//Gmail's SMTP port ASmtp. Credentials =NewNetworkCredential ("","123456"); -Smtp. Enablessl =true;//gmail requires SSL connection -Smtp. Deliverymethod = Smtpdeliverymethod.network;//the way Gmail is sent is through the network, you need to specify theSmtp. Send (MyMail);

Example of sending mail using QQ mailbox

1MailMessage MyMail =NewMailMessage ();2Mymail.from =NewMailAddress ("");3MYMAIL.TO.ADD (NewMailAddress (""));4Mymail.subject ="C # Send email";5Mymail.subjectencoding =Encoding.UTF8;6Mymail.body ="This was a test email from qq!";7Mymail.bodyencoding =Encoding.UTF8;8mymail.isbodyhtml =true;9SmtpClient SMTP =Newsmtpclient ();TenSmtp. Host ="smtp.qq.com"; OneSmtp. Credentials =NewNetworkCredential ("","123456"); ASmtp. Send (MyMail);

"Go" C # send an email message

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.