简体   繁体   中英

schedule Email in asp.net, C#

I want to schedule the email with asp.net and C# code.

what is basic idea or code for schedule email?

Use a scheduler perhaps? Quartz.NET is a pretty decent one.

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.

Then have a process that runs every x minutes and sends all emails where 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. 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.

The most simple way to differ the sending of email is to schedule a task in the windows scheduled tasks tool. This task is a simple call to a vbs file. This vbs file open an url from your web application. Behind this url, put a webpage that do your scheduled work inside the app, in this case, the sending of emails. It doesn't need windows service, just a simple 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.

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.

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. If you start down this road and need some more help let us know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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