tags:

views:

606

answers:

5

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

what is basic idea or code for schedule email?

+2  A: 

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.

Steve Danner
i don't want to start my computer at all time.i want to set on my hosting server.i stay in india and server at US. i cant not install any manual software or console application at their. so waht i should od?
AjmeraInfo
If I understand you correctly, you want to fire off an email on a server that you can't install any software on? I think your only option might be Albert's option of running it from a SQL job.
Steve Danner
+2  A: 

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

Regards

bgs264
While both answers so far would work, I've found in the past that setting up a job in the database that kicks off this process to be easier to configure and set up than using scheduled tasks.
Zhaph - Ben Duguid
A: 

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?&amp;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.

Albert
ouch. can someone tell me why this is a bad suggestion? we use this method for a couple applications and it works beautifully...whats so wrong with it?
Albert
A: 

Hi,

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.

Pierre
+1  A: 

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.

Vinzz