简体   繁体   English

在 asp.net 中安排电子邮件,C#

[英]schedule Email in asp.net, C#

I want to schedule the email with asp.net and C# code.我想用 asp.net 和 C# 代码安排电子邮件。

what is basic idea or code for schedule email?日程安排电子邮件的基本思想或代码是什么?

Use a scheduler perhaps?也许使用调度程序? Quartz.NET is a pretty decent one. Quartz.NET是一个相当不错的。

I assume you already know how to send a mail, so just schedule a new job, and roll with it.我假设您已经知道如何发送邮件,所以只需安排一个新工作,然后继续。

You could have a database table EmailSchedule(ID, SendTo, Subject, MessageBody, SendDateTime) When you want to schedule an email to be sent, write to the table.您可以有一个数据库表 EmailSchedule(ID, SendTo, Subject, MessageBody, SendDateTime) 当您想要安排发送电子邮件时,请写入该表。

Then have a process that runs every x minutes and sends all emails where SendDateTime <= Now然后有一个进程每 x 分钟运行一次并发送所有电子邮件,其中 SendDateTime <= Now

Try just writing a simple console app that sends the email and using Windows Task Scheduler to run it when you need it.尝试编写一个简单的控制台应用程序来发送电子邮件,并在需要时使用 Windows 任务计划程序运行它。 Sending an email is a pretty standard task, like Will said, there are plenty of similar questions pertaining to it on here already, but if you have a look at the System.Net.Mail namespace, that should get you started.发送电子邮件是一项非常标准的任务,就像 Will 所说的,这里已经有很多与此相关的类似问题,但是如果您查看System.Net.Mail命名空间,那应该会让您入门。

The most simple way to differ the sending of email is to schedule a task in the windows scheduled tasks tool.区分电子邮件发送的最简单方法是在 Windows 计划任务工具中计划任务。 This task is a simple call to a vbs file.此任务是对 vbs 文件的简单调用。 This vbs file open an url from your web application.这个 vbs 文件从您的 Web 应用程序打开一个 url。 Behind this url, put a webpage that do your scheduled work inside the app, in this case, the sending of emails.在这个 url 后面,在应用程序中放置一个执行您预定工作的网页,在这种情况下,是发送电子邮件。 It doesn't need windows service, just a simple vbs.它不需要windows服务,只需要一个简单的vbs。 The called page is in your app, so no need to do some extra work to interface data or treatment outside of the web app.被调用的页面在您的应用程序中,因此无需做一些额外的工作来在 Web 应用程序之外进行数据接口或处理。

Hope this will help,希望这会有所帮助,

Regards,问候,

Pierre.皮埃尔。

You could have a table in SQL called mailToBeSent or something like that...and each time you want to schedule an email, insert an email into that table with all the appropriate data elements (subject, to, cc, body etc), and most importantly have a field for date/time to be sent, and have a SQL job run every 5/10/15 minutes or whatever you choose, and check that table for mail that needs to be sent...send the message, and delete the record on success.你可以在 SQL 中有一个名为 mailToBeSent 或类似的表......每次你想要安排一封电子邮件时,将一封带有所有适当数据元素(主题、收件人、抄送、正文等)的电子邮件插入该表中,并且最重要的是有一个用于发送日期/时间的字段,并且每 5/10/15 分钟或您选择的任何时间运行一次 SQL 作业,并检查该表中是否有需要发送的邮件......发送消息,然后删除成功记录。

I know someone who uses this setup and it works beautifully.我知道有人使用这种设置,而且效果很好。 Unfortunately I don't have his code, but a few google searches for each piece of the process might prove fruitful.不幸的是,我没有他的代码,但是对每个过程的每个部分进行几次谷歌搜索可能会证明是富有成效的。

Here's a start: http://www.google.com/search?&q=how+to+use+sql+job+table+to+send+emails The first set of links look good.这是一个开始: http://www.google.com/search?&q=how+to+use+sql+job+table+to+send+emails第一组链接看起来不错。 If you start down this road and need some more help let us know.如果您开始走这条路并需要更多帮助,请告诉我们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM