C # email sending program

Source: Internet
Author: User

A simple winform email sending program implemented in C # is as follows:

 

Drag Textbox, label, and button in the design interface. For details, see:

 

The code for clicking an event on the send button is as follows:

 

Private void btnsend_click (Object sender, eventargs E)

{

Smtpclient mailclient = new smtpclient ("mail.sina.com"); // SMTP server name;

Mailclient. Credentials = new networkcredential ("xxx@sina.com", "***"); // user name and password;

Mailaddress from = new mailaddress ("xxx@sina.com"); // sender address;

Mailaddress to = new mailaddress(this.txt mailto. Text );

Mailmessage message = new mailmessage (from, );

 

Message. Subject = this.txt subject. text;

Message. Body = This. rtxtcontent. text;

If (this.txt cc. Text. Trim ()! = "")

{

Mailaddress copy = new mailaddress(this.txt cc. Text. Trim ());

Message. CC. Add (copy );

}

 

Try

{

Mailclient. Send (Message );

MessageBox. Show (this, "prompt", "sent successfully! ", Messageboxbuttons. OK, messageboxicon. Information );}

Catch (exception ex)

{

Throw ex;

}

}

 

Reference to be added:

Using system;

Using system. Windows. forms;

Using system. net. mail;

Using system. net;

 

In this way, a simple email sending program is completed ~~~

Of course, you can modify the Group Sending and email template functions on this basis.

Currently, most free emails on the Internet do not provide free SMTP services. It is said that Sina still can do it... the code above can be sent through my company email test ~

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.