C # Mail sending

Source: Internet
Author: User
Tags mail account mailmessage smtpclient

1. Tools and resources used: VS2012 provides smtpclient class (System.NET.Mail) in the. NET Frameword class Library

2. Operation

3, the specific code implementation

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;usingSystem.Net.Mail;usingSystem.Net.Mime;usingSystem.Net;usingSystem.IO;namespaceIntelligent Monitoring based on human face recognition { Public Partial classContact Us: Form { PublicContact Us () {InitializeComponent (); }        Private voidYes_click (Objectsender, EventArgs e) {            if(Usertext. Text = ="") {MessageBox.Show ("you don't have to enter any content! "); }Else            Try            {                //determine the SMTP server address. Instantiate an SMTP clientSystem.Net.Mail.SmtpClient client =NewSystem.Net.Mail.SmtpClient ("smtp.qq.com", -);//pop.exmail.qq.com//smtp.qq.comClient. Enablessl =true;//specify smtpclient to use Secure Sockets Layer (SSL) encrypted connections//generate a Send address                stringStrfrom ="[email protected]"; //constructs a sender address objectMailAddress from=NewMailAddress (Strfrom,"Providence", Encoding.UTF8); //constructs a recipient address objectMailAddress to =NewMailAddress ("[email protected]","Fate", Encoding.UTF8); //construct a Message object for an emailMailMessage message =NewMailMessage ( from, to); //add message subject and contentMessage. Subject ="Subject: User Comments" ; Message. Subjectencoding=Encoding.UTF8; Message. Body="content: Test messages"+ Usertext. Text;//The content that is sent when the user enters the textMessage. Bodyencoding =Encoding.UTF8; //set information for a messageClient. Deliverymethod =smtpdeliverymethod.network; Message. Bodyencoding=System.Text.Encoding.UTF8; Message. Isbodyhtml=true; //set the user name and password. Client. useDefaultCredentials =false; stringUsername ="227*******";//your e-mail account                stringpasswd ="ESSC*********HC";//your authorization code, your password cannot login, the authorization code for a serial number such as esscncukoftqe**** application address https://mail.qq.com///User Login InformationNetworkCredential mycredentials =Newnetworkcredential (username, passwd); Client. Credentials=mycredentials; //Send mailclient.                Send (message); MessageBox.Show ("Mail sent successfully, thank you for your support! "); }            Catch{MessageBox.Show ("message failed to send"); }        }    }}

4, simple send the function of the mail to realize! Please give us a lot of advice!!! Thank you!!!!

5. Acknowledgement: Thanks to the vast number of Bo friends have selfless dedication!

C # Mail sending

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.