Send a message in a wave of C #

Source: Internet
Author: User
Tags email 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 is as follows:

Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.threading.tasks;using system.windows.forms;using System.Net.Mail; Using System.net.mime;using system.net;using System.IO; namespace windowsformsapplication1{public partial class Form1:form {public Form1 () {in        Itializecomponent (); }//Based on AI-oriented design private void Form1_Load (object sender, EventArgs e) {} private void btn OK_Click (object sender, EventArgs e) {if (yes. Text = = "" | | txttestname.text== "") {MessageBox.Show ("You did not enter anything!")            "); }else try {//To determine the SMTP server address. Instantiate an SMTP client System.Net.Mail.SmtpClient = new System.Net.Mail.SmtpClient ("smtp.qq.com");//pop.ex mail.qq.com//smtp.qq.com Client. Enablessl = true;//Specifies smtpclient use Secure Sockets Layer (SSL) Encrypted connection//Generate a Send address string strfrom = "[email protected]";                Constructs a sender Address object mailaddress from = new MailAddress (strfrom, "Providence", Encoding.UTF8);                Constructs a recipient address object mailaddress to = new MailAddress (Txttestname.text, "fate", Encoding.UTF8);                Constructs an email message object MailMessage message = new MailMessage (from, to); Add message subject and content message. Subject = "Subject: Smina user test!"                " ; Message.                subjectencoding = Encoding.UTF8; Message. Body = "Content: Test message" + Yes. Text; The text that is sent by the user enters a message.                bodyencoding = Encoding.UTF8; Sets the message client.                Deliverymethod = Smtpdeliverymethod.network; Message.                bodyencoding = System.Text.Encoding.UTF8; Message.                Isbodyhtml = true;                Set the user name and password. Client.                useDefaultCredentials = false; string username = "[EmaiL protected] "; Your email account string passwd = "IPZUUXXXXXBJJB";//Your authorization code, your password can not be logged in, the authorization code for a serial number such as esscncukoftqe**** application address https://mail.qq                . com///User login information NetworkCredential mycredentials = new NetworkCredential (username, passwd); Client.                Credentials = mycredentials; Send mail client.                Send (message); MessageBox.Show ("Mail sent successfully, thank you for your support!")            ");            } catch {MessageBox.Show ("message sent Failed"); }                }    }}

  

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!

Send a message in a wave of C #

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.