YYW'S BLOG 我思故我在

知识的分享就是知识的获得
posts - 73, comments - 272, trackbacks - 4, articles - 0
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理
一个基于 .NET 2.0 System.Net.Mail namespace 的邮件发送接收组件,参考了以前网上一些基于 System.Web.Mail namespace 例子。


测试程序
 

下载


2006-8-16
    最近做的项目需要群发邮件,发现上面的SMTP类每发送一封邮件必须创建创建一个实例,这无疑是对系统资源的浪费,所以重构了一下,结果如下,推荐大家使用下面的实现方法

Feedback

#1楼   回复  引用    

2006-07-11 19:11 by yyy[未注册用户]
多谢

#2楼   回复  引用    

2006-07-17 15:13 by cdlkjds[未注册用户]
初步看了一下源吗,不错。

#3楼[楼主]   回复  引用  查看    

2006-07-17 21:36 by 思考中{OO}      
@cdlkjds
源码大部分来自网上,其实我只是给它稍加了修改,添加了一些自己的东西 :)
感谢所有无私奉献的同志们

#4楼   回复  引用    

2006-07-20 18:10 by yyy[未注册用户]
运行后发现:
如果我的邮箱服务器是不需要验证用户名密码就可以登录的,那输入的用户密码为空,则不能发送成功。
还有想问问这个组件里的 Mailer中的Constructors中的构造函数里,发件人的信息是从配置文件里读的,
NetSectionGroup.GetSectionGroup(config).MailSettings 这句是读取config中的MailSettings配置节的信息,可是config文件中并没有哪个section的name是MailSettings 啊 请问下这个是从哪里读出来的啊?

#5楼   回复  引用    

2006-07-20 18:11 by yyy[未注册用户]
我运行代码,不能断点调试,所以也找不出是从哪里读出来的,还望多多赐教

#6楼   回复  引用    

2006-07-21 11:08 by zzj[未注册用户]
config文件中
<system.net>
<mailSettings>
<!-- these settings define the mail server settings
from: the user name from which the email is sent - this is the application that is sending the message
host: the name of your mail server
userName: the name the application will use to log into the mail server
password: the password for the above user name
-->
<smtp from="admin@your-domain.com">
<network host="your-mail-server-name"
userName="your-user-name"
password="your-password" />
</smtp>
</mailSettings>
</system.net>

#7楼[楼主]   回复  引用  查看    

2006-07-22 22:03 by 思考中{OO}      
@yyy
能说明一定具体情况吗?是不是设置了断点后是一个空心的圆圈,里面有一个感叹号,记得以前遇到过这种情况,你重新生成解决方案试试

#8楼   回复  引用  查看    

2006-08-15 10:56 by 川仔      
异步发送是什么意思,能返回什么状态吗?
SmtpMail.SendAsync(Email, userState);

#9楼[楼主]   回复  引用  查看    

2006-08-15 15:30 by 杨炎武