当前位置: 代码迷 >> ASP.NET >> [] 一个自动发送邮件有关问题?(加急〉)
  详细解决方案

[] 一个自动发送邮件有关问题?(加急〉)

热度:7445   发布时间:2013-02-25 00:00:00.0
[求助] 一个自动发送邮件问题??(加急--〉在线等)
比如说   每天00:00搜索一遍数据库  
如果DateTime.Now   ==   用户生日  
自动给其发邮件
(以前没做过   求详细思路   最好有个简单的例子--〉有中文注释更佳)

是不是要用线程?
如果是怎么定义这个线程?
怎么在00:00启用这个线程??

请大虾帮忙
:)

------解决方案--------------------------------------------------------
最近正在研究,关注。。。。。。。。。。。。


protected void Page_Load(object sender, EventArgs e)
{

this.Timer1.Enabled = true;
this.Timer1.Interval = 1000;
}
protected void Timer1_Tick(object sender, EventArgs e)
{
string CurrTime = System.DateTime.Now.ToString( "hh:mm:ss ");
if (CurrTime == "11:00:00 ")
{
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage( "from ", "to ", "测试定时 ", "测试定时发邮件 ");
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient( "smtp.163.com ");
client.Credentials = new System.Net.NetworkCredential( "name ", "password ");
try
{
client.Send(message);
}
catch (Exception ex)
{
SQLHelper.CreateErrorMsg(ex.Message);
}
}
}
------解决方案--------------------------------------------------------
在Global.asax文件中定义一个timer,让这个timer每5分钟执行一次判断时间函数(判断当前时间是否是0点,这里也可以让timer每24小时执行一次),如果现在是0点那麽就执行你的发邮件函数,将满足条件的数据都遍历一遍。
------解决方案--------------------------------------------------------
关注一下,学习
------解决方案--------------------------------------------------------
up
------解决方案--------------------------------------------------------
我来帮顶
------解决方案--------------------------------------------------------
..winform 还不简单

直接拖一个Timer 控件,设置时间间隔,

在Timer事件里写

if(DateTime.Now == 你要的){
开始操作
}
  相关解决方案