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

推荐订阅源

腾讯CDC
N
Netflix TechBlog - Medium
Google DeepMind News
Google DeepMind News
Scott Helme
Scott Helme
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
月光博客
月光博客
有赞技术团队
有赞技术团队
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
WordPress大学
WordPress大学
Jina AI
Jina AI
M
MIT News - Artificial intelligence
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
阮一峰的网络日志
阮一峰的网络日志
B
Blog RSS Feed
P
Proofpoint News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Fortinet All Blogs
Y
Y Combinator Blog
Microsoft Azure Blog
Microsoft Azure Blog
云风的 BLOG
云风的 BLOG
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
I
InfoQ
Vercel News
Vercel News
C
Check Point Blog
美团技术团队
V
V2EX
量子位
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
G
Google Developers Blog
博客园_首页
J
Java Code Geeks
Recent Announcements
Recent Announcements
人人都是产品经理
人人都是产品经理
H
Help Net Security
博客园 - Franky
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
T
Tailwind CSS Blog
IT之家
IT之家
S
SegmentFault 最新的问题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
L
LangChain Blog
博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - 君

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