views:

69

answers:

2

Hi

I am using

  • asp.net mvc 2.0
  • C#
  • .NET 4.0
  • ms sql server 2005
  • iis 7.0

I want to make an email notifier system just like many sites have such as google. I want user to be able to set a reminder date and when that date is hit a email is sent to them.

I am not sure how to do this.

I heard of a couple ways but have not found any tutorials on how to do them.

  • Windows scheduler
  • through ms sql server (think sql server agent?)

With the windows scheduler I don't think it would work on a shared hosting environment. I would prefer if it did but if there is a big difference then I can live with out that ability.

I also want in the very near future to support SMS messages so the solution should be able to expand to work with that as well if possible.

+1  A: 

This blog post presents a very effective (though somewhat 'hacky') solution to your problem that will work in a shared hosting environment. This is what Jeff used in StackOverflow to assign badges to users (I don't know if SO is still using it though).

For the code to actually send the email, you should look around the Internet since there are endless code examples on how to do that. One possible answer could be:

    public void SendEmail()
    {
        MailMessage loMsg = new MailMessage();

        loMsg.From = new MailAddress("[email protected]");
        loMsg.To.Add(new MailAddress("[email protected]"));
        loMsg.Subject = "Subject";
        loMsg.Body = "Email Body";


        var smtp = new SmtpClient
        {
            Host = "smtp.gmail.com",
            Port = 587,
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            UseDefaultCredentials = false,
            Credentials = new System.Net.NetworkCredential("username", "password")
        };

        smtp.Send(loMsg);
        }

Take a look and see if it helps

Kiranu
A: 

@chobo2, you can use quartz.net to check for due tasks (say, every one minute) and take some action (like sending an email) when a task has a due date less than the current date and the task was not notified.

So you will have to have a due date property in your task and a bit indicating if it has been notified. Every minute, you run code that looks for tasks with due date less than or equal than the current date and for each of them you send a notification email. Then you mark the task as notified.

Regards.

uvita