比较顺利。。。
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 using System.Net.Mail; 11 12 namespace WindowsFormsApplication2 13 { 14 public partial class Form1 : Form 15 { 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 21 private void button1_Click(object sender, EventArgs e) 22 { 23 string file = "E:\\bar.txt"; 24 MailAddress from = new MailAddress("aguncn@163.com"); 25 MailAddress to = new MailAddress(textBox2.Text); 26 MailMessage message = new MailMessage(from, to); 27 message.Subject = textBox1.Text; 28 message.Body = richTextBox1.Text; 29 Attachment myAttachment = new Attachment(file, System.Net.Mime.MediaTypeNames.Application.Octet); 30 System.Net.Mime.ContentDisposition disposition = myAttachment.ContentDisposition; 31 disposition.CreationDate = System.IO.File.GetCreationTime(file); 32 disposition.ModificationDate = System.IO.File.GetLastWriteTime(file); 33 disposition.ReadDate = System.IO.File.GetLastAccessTime(file); 34 message.Attachments.Add(myAttachment); 35 SmtpClient client = new SmtpClient("smtp.163.com", 25); 36 client.Credentials = new System.Net.NetworkCredential("aguncn@163.com", "********"); 37 client.Send(message); 38 MessageBox.Show("发送成功"); 39 40 } 41 } 42 }
时间: 2024-09-14 05:17:19