0

I am sending mails from my codes, for some activities.

But some mails may fail due to some or other reason.

I am keeping details of all such failed mails in a table.

Now my plan is to periodically check that table and resend mails if the table contain failed mails.

Or in other words,I want to call a method SentFailedMails() in every 12 hours.

How can I do this is c#

My application is a WCF service,Hosted on IIS

Kuttan Sujith
  • 7,889
  • 18
  • 64
  • 95
  • 1
    Is your application a service which runs 24/7? – ZoolWay Sep 02 '15 at 08:32
  • 2
    Use the windows taskscheduler and run a custom exe. – rene Sep 02 '15 at 08:33
  • use windows services or job – Nalaka Sep 02 '15 at 08:34
  • I don't think there is such things in mvc.It's better you write windows service for this task and then install on your webserver to resend email – Arash Sep 02 '15 at 08:35
  • Perhaps. Then again, the last thing the world wants is _another_ Windows Service with a built-in scheduling component. Consider using the standard _Task Scheduler_ as rene mentioned instead and have it run your regular non-service .EXE. Plus it's kinder to puppies –  Sep 02 '15 at 08:37
  • My application is WCF service – Kuttan Sujith Sep 02 '15 at 08:38
  • 1
    @KuttanSujith Great! What _sort_ of WCF service? Where is it hosted? _IIS? WinForms? WPF? Custom host .exe?_ A WCF Service _inside a Windows Service_? –  Sep 02 '15 at 08:40
  • You can mark the temporarily failed emails in a table in database. Now you can write another windows service which can have a timer to resend your emails. Or you can write a simple console application for re-sending emails and call this application from Windows Task Schedular – M_Idrees Sep 02 '15 at 08:46
  • Have a look at [this answer](http://stackoverflow.com/a/6899188/706456) – oleksii Sep 02 '15 at 08:52
  • 1
    can you use `httpmodule` ? I mean global.asax file ? – Shaminder Singh Sep 02 '15 at 08:53
  • Yes I can use global.asax – Kuttan Sujith Sep 02 '15 at 15:13
  • Please explain what can i do if i can use global.asax? – Kuttan Sujith Sep 09 '15 at 05:20

3 Answers3

1

Create a very simple console application that do the task (move your SentFailedMails() method to this application and execute it on run).

Place the exe file for the console application in a folder of your server.

Use Windows Task Scheduler to schedule the exe file execution for every 12 hours or on any specific time.

Ppp
  • 1,015
  • 9
  • 14
  • Windows Task Scheduler is a ready to use thing from windows. You can set it to execute a program in specific times of the day. Non developer can use it. [link](http://www.7tutorials.com/how-create-task-basic-task-wizard) Workflow foundation is more towards developing your own scheduler. I think. – Ppp Sep 02 '15 at 11:49
1

You might want to use a scheduler like Quartz.net

tobsen
  • 5,328
  • 3
  • 34
  • 51
0

You can use a threading.timer and set it to 12:00:00 then give it your mail method to execute . Don't forget about the dispatcher to change thread though.

Augure
  • 360
  • 3
  • 13