C # using SMTP to send attachments

There are stocks of enthusiasm to learn C # a few years ago, wrote the e-mail article C # and C # to send mail sent with an attachment, put it on baidu. There have previously put on ttlsa, but the search found articles seemingly been deleted, specially re-add today. This article is reserved for recording. In addition to the simple code for sending a message, it also comprises a transmission attachments. From FIG not posted, two buttons on the top, an "Add attachment", a "transmission." Click Add to select the file attachment, the file path stored in listbox1 in full. In the Send button method, add listbox1 all files sent as e-mail mailmessage objects inside out, look at the code using System; using System.ComponentModel;; using System.Collections.Generic using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Net.Mail; using System.Net; using System.Net.Security; using System.IO; using System.Net.Mime; namespace SmtpTest {public partial class Form1 : Form {public Form1 () {InitializeComponent ();} private void button1_Click (object sender, EventArgs e) {try {// definition of a mail subject MailMessage mailmessage = new MailMessage ( "", "", "this is a test" , "! yes test!"); // from email, to email, subject, message content mailmessage.Priority = MailPriority.Normal; Operation and maintenance lifetime     URL: http: //www.ttlsa.com/html/3456.html

Reproduced in: https: //my.oschina.net/766/blog/210939

Guess you like

Origin blog.csdn.net/weixin_33694172/article/details/91493010