-2

I just met a situation which was to send a verification email to the newly registered user after one hour of their subscription.

Let us consider a website: www.sample.com and to this website any number of users may register to it. After registration has been completed, I have to send them the verification email after an hour from their registration time.

I am using Sql Server 2008r2 for DB storage.

How can I send the verification email after an hour from their registration time?

Christoph Fink
  • 22,727
  • 9
  • 68
  • 113
RajeshKannan
  • 894
  • 2
  • 16
  • 32
  • 5
    There's a lot of ways to accomplish this. Are you allowed to use background Windows services? What have you tried? – Steven V May 19 '14 at 13:17
  • 2
    This is too vague to answer. What have you tried? What database are you using? Do you have access to Exchange, SMTP server etc? – Peter Smith May 19 '14 at 13:18
  • Give us more info please. – Thanos Markou May 19 '14 at 13:21
  • @PeterSmith I'm using sql server 2008r2 for storage and also have access to smtp server. – RajeshKannan May 19 '14 at 13:22
  • @StevenV I thought about using window service but we need to use thread.sleep for each request, right? Does using thread.sleep in this case is efficient? – RajeshKannan May 19 '14 at 13:25
  • 2
    @RajeshKannan The windows service would monitor the backing storage to find new registrations. Then one hour after the registration was completed it would send the email. – Steven V May 19 '14 at 13:28
  • I'd say you should avoid `Thread.Sleep` as much as possible and instead try using one of the `Timer` classes or perhaps `Task.Delay`. – julealgon May 19 '14 at 13:28
  • You're basically looking for scheduled tasks, see this http://stackoverflow.com/a/542831/231316 – Chris Haas May 19 '14 at 13:55
  • @ChrisHaas if hundreds of user registers at a time, does scheduled tasks causes any problem? – RajeshKannan May 19 '14 at 14:04
  • 1
    Depends on how you build it. As with anything on the web, you should assume the worst and build for that. Like the post I noted, have your task call a webpage and put your logic in the page. That page should say "give me N registered users that are at least 1 hour old and haven't been sent their email yet". For each user, send the email and flag them as sent. Keep `N` low to avoid timeouts. Have your task run every `M` minutes. `M` can probably be every 5 minutes but you'll need to play with it. – Chris Haas May 19 '14 at 14:11
  • @PeterSmith I actually disagree on this case. I think the question is precise enough to show the problem he is having. I think it should be answered with the level of abstraction needed, which is what I tried to do. – julealgon May 19 '14 at 15:55

2 Answers2

5

The whole asp.net platform is not designed for this kind of task. It should process the request and respond as fast as possible due to the stateless nature of http.

Any long running or delayed job like this is better done on a separate application. You can use a Windows Service in this case, like Steven suggested, or a Workflow application.

Of course, you will have to communicate to the service that the user registered somehow, using WCF, an ESB or via a shared database polling for instance.

julealgon
  • 7,072
  • 3
  • 32
  • 77
0

You have to create a job. search job in sql server for more information.

chandresh patel
  • 309
  • 1
  • 10