您的位置:首页 > 编程语言 > C#

C#之SYSTEM.NET.MAIL类演示例子

2013-06-12 10:35 141 查看
比较顺利。。。

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;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string file = "E:\\bar.txt";
MailAddress from = new MailAddress("aguncn@163.com");
MailAddress to = new MailAddress(textBox2.Text);
MailMessage message = new MailMessage(from, to);
message.Subject = textBox1.Text;
message.Body = richTextBox1.Text;
Attachment myAttachment = new Attachment(file, System.Net.Mime.MediaTypeNames.Application.Octet);
System.Net.Mime.ContentDisposition disposition = myAttachment.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
message.Attachments.Add(myAttachment);
SmtpClient client = new SmtpClient("smtp.163.com", 25);
client.Credentials = new System.Net.NetworkCredential("aguncn@163.com", "********");
client.Send(message);
MessageBox.Show("发送成功");

}
}
}




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: