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

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - Tiu

2010走了,又是一年,留个脚印 Commerce Server 2007 随笔一 2009眨眼间过去了,留个纪念 asp.net ajax随笔二 asp.net中慎用static全局变量 asp.net ajax随笔一 收集的关于依赖注入及Unity application block入门的一些资料 2008最后一篇:总结与展望 文件操作类简介 防止页面在提交的过程中多次点击按钮 第一次使用SQLCLR C#网络编程随笔一 装AJAX.NET 1.0的环境,我遇到个问题,进来解答下 XML学习一 asp.net窗中的两个Form问题 URL重写入门 动态从数据库中选择Top 个数 关于在数据层返回SqlDataReader 编写类和子程序的几个原则
关于邮件群发
Tiu · 2007-01-12 · via 博客园 - Tiu

      这两天在给网站弄邮件群发功能,关于实现发邮件就是利用.Net自身提供的System.Web.Mail空间中的一些方法实现,下面先列出仅仅发邮件的代码:

                MailMessage objMessage=new MailMessage();
                objMessage.To
="对方邮箱";
                objMessage.From
="邮箱";
                objMessage.Subject
="邮件标题";
//                objMessage.Attachments.Add(new MailAttachment(""));//发送附件
                objMessage.BodyFormat=MailFormat.Html;
                objMessage.BodyEncoding
=Encoding.GetEncoding("GB2312");
                objMessage.Body
=""邮件内容;
//                objMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1);
//                objMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username");
//                objMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password");
                SmtpMail.SmtpServer = "192.192.1.53";
                SmtpMail.Send(objMessage);

由于我用的本机的SMTP服务所以不用身份验证,就注释掉了下面的三行。这样就能把邮件发送出去了,然后就考虑群发怎么实现,我参考的是CS里邮件群发的代码。是先把想要发送的所有邮件存储到数据库中,然后让单独的一个线程在后台自己发送,这样就避免的我们等待的过程,我们只需把邮件存到数据库里就显示成功。
      我是在Global.asax的Application_Start方法里初始化一个Timer,注意这里的Timer是System.Threading命名空间中的类,使用 TimerCallback 委托指定希望 Timer 执行的方法。计时器委托在构造计时器时指定,并且不能更改。此方法不在创建计时器的线程中执行,而是在系统提供的线程池线程中执行。更具体的解释请参照MSDN。然后自己定义一个callback方法调用发送邮件的方法。
      其实只要会了发送一封就会群发了,循环就行,由于我是把发送的所有邮件都放到数据库里,所以再循环的时候发送一封就删除一封,失败的保留。当循环一遍后,假若有失败为发送成功的会继续保留在数据库里,在下一次出发Timer时会发送,当然最好设置下发送次数,比方说发送十次不成功就不再发送,然后把邮件从数据库中删除。大量发送本人还没测试,慢慢完善。在这只提供个思路。