100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > ASP.NET 定时发送邮件

ASP.NET 定时发送邮件

时间:2022-03-28 18:12:08

相关推荐

ASP.NET  定时发送邮件

定时发送邮件就是设定一个时间点,每当系统判断到达设定的时间点的时候,,便会触发发送邮件的事件

定时发送邮件的代码写在Global.aszx中,系统自动运行

1.Application_Start()中设定一个定时器以及邮件发送事件

protected void Application_Start(object sender, EventArgs e){System.Timers.Timer timer = new System.Timers.Timer(30000);timer.Elapsed += new System.Timers.ElapsedEventHandler(Send);timer.Start();}

2.对Send()方法进行编辑,设定发送的时间、发送邮箱和接收邮箱

public void Send(object sender, System.Timers.ElapsedEventArgs e){if (DateTime.Now.Minute == 17){//endEMail sm = new SendMail();SendEMail("6576754545@", "6576754545@","Time Mail", "This is time!");}}

DataTime.Now. xx 可以按照自己的需求去选择发送邮件的间隔

3.对SendEmail()方法进行编写

public void SendEMail(string To1, string CC1, string Subject1, string Body1){MailMessage msg = new MailMessage("接收邮箱@", To1);.Add(CC1);msg.Subject = Subject1;msg.Body = Body1;msg.IsBodyHtml = true;msg.Priority = MailPriority.High;//发送邮件的优先等级 SmtpClient c = new SmtpClient("", 587);workCredential basicAuthenticationInfo =new workCredential("6576754545@", "xxxxxxxxxx");//用户名与SMTP授权码c.Credentials = basicAuthenticationInfo;c.EnableSsl = true;//启用SSL加密 c.Send(msg);}

MailMessage类是邮件信息类,通过From属性可以设置发送者。To属性设置接受者。CC抄送者。

Subject 标题;Body、内容。

4.新建一个web窗体,运行程序

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。
相关阅读
ASP.NET发送邮件|

ASP.NET发送邮件|

2021-07-30

ASP.NET--邮件发送

ASP.NET--邮件发送

2018-09-11

asp.net 发送邮件代码

asp.net 发送邮件代码

2024-04-26

ASP.net实现邮件发送

ASP.net实现邮件发送

2021-03-24