惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
F
Fortinet All Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
V
Visual Studio Blog
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
L
LangChain Blog
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
IT之家
IT之家
P
Proofpoint News Feed
博客园_首页
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Check Point Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - 君

50口诀让你轻松记四六级单词 苦瓜炒蛋 随笔 将货币数字描述转化成中文描述 - 君 - 博客园 年旦前 经历一劫 2007-12-16 随缘也 留脚 一篇不错的文章 .net修改网络配置,如IP,DNS等 2007-2-3 2006-12-23 .NET中获取系统硬件信息 网站宣传 用C#播放声音文件 DotNetMagic做应用程序界面(类似office2003风格) Grove——.NET中的ORM实现(转载,学习...........)
.net写发送邮件工具
· 2007-02-09 · via 博客园 - 君

具体发送邮件的命名空间System.Net.Mail下有很多方法,下面是复制的代码;
具体的界面自己画一下就可以了,应该看的懂,具体代码如下:

 1private void button1_Click(object sender, EventArgs e)
 2
 3        {//发送
 4
 5            string strRecieveEMail = txtRecieveEMail.Text.Trim();
 6
 7            string strSendEmail = txtSendEMail.Text.Trim();
 8
 9            string strSubject = txtSubject.Text.Trim();
10
11            string strBody = txtBody.Text.Trim();
12
13 
14
15            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
16
17            msg.To.Add(strRecieveEMail);
18
19 
20
21            //System.Net.Mail.MailAddress mAdd = 
22
23 
24
25            if(txtAttachment.Text.Trim().Length > 0)
26
27            {
28
29                string FileName = txtAttachment.Text.Trim();
30
31                System.Net.Mail.Attachment pAttachment = new Attachment(FileName);
32
33                msg.Attachments.Add(pAttachment);
34
35            }

36
37            
38
39            msg.From = new MailAddress(strSendEmail, strSendEmail, System.Text.Encoding.UTF8);;
40
41            /* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/
42
43            msg.Subject = strSubject;//邮件标题             
44
45            msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码 
46
47            msg.Body = strBody;//邮件内容 
48
49            msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码 
50
51            msg.IsBodyHtml = false;//是否是HTML邮件 
52
53            msg.Priority = MailPriority.High;//邮件优先级 
54
55 
56
57 
58
59            SmtpClient client = new SmtpClient();
60
61            client.Host = txtSmtp.Text.Trim();//这个非常重要,为邮件服务器设置
62
63 
64
65            object userState = msg;
66
67            try
68
69            {
70
71                client.SendAsync(msg, userState);    //简单一点儿可以client.Send(msg); 
72
73                MessageBox.Show("成功发送到" + strRecieveEMail + "邮箱");
74
75            }

76
77            catch (System.Net.Mail.SmtpException ex)
78
79            {
80
81                MessageBox.Show(ex.Message, "发送邮件出错");
82
83            }

84
85        }

86