views:

93

answers:

5

I have to add e-mail notifications to a client server application.

Notifications happen as the user do some particular action on the client UI.

If I had a middle tier or a service running at server I can imagine how to do it:

1) I simply create a DB tables with "pending notifications"

2) as a user does an action that generates a notification I add a record to the table

3) serverside I would continuously try to send those mails and removing them from the table once sending is succesful

Now I cannot do this now, I have a plan to add a service later on, but for now I must go the quick and dirty way.

So somehow what I was thinking to is to implement something like this:

1) as a notify-worth event occurs at client, the same client (my exe) tries to send the notification, upon failure it will log the notification in the "pending notifications" table (failure can be becuase lack of internet connection or any other problem)

2) I add a Timer that will work from any client machine to check for pending notifications. If there are any the client will try to send the e-mail (using a transaction: I will mark a field as "TryngToSendFromClientX" and in case of failure I will reset that field to NULL)

I think this approach would work, it has obvious limitations (if after failure no one logs into the system, no notification will be sent - same would be if service goes "down"). But can you comment on this approach and suggest a better one?

Additional notes (to better understand the scenario):

a) Note: all notifications are sent from the same e-mail account.

b) I don't need to keep track of who sent the e-mail.

c) the problem of creating the service now is that it will basically complicate significantly deployment and I need to create tools for monitoring the status of the service. Something that I will do in future but not now, in future I have plan to add more functionality (not only sending notifications) to the service, so in that case it makes more sense to create it.

d) I will send e-mails by using Indy components and SMTP server.

+1  A: 

Perhaps you can add a parameter to your client which causes it to just look at the pending notifications and send them. After this it can terminate itself. It will just act like some kind of service.

Then you install the client on the server and start it every x minutes.

bepe4711
mmmm.... Leaving a "idle" running client on the server is really not a bad idea. It is in the quick and dirty domain, but effective.
If you're going to write a service later on, i would not put in much effort to find a solution right now. Do it quick and dirty so you got more time for the "real" service...
bepe4711
Yes I agree. Investing to much for a temporary solution is a waste of time and money. If quick and dirty makes the job in an acceptable manner (alternative is "no job at all") it is already an improvement. Then the future "real" implementation will be the final choice.
+2  A: 

If you are not willing to create the service now, I think you are stuck with the scenario you describe. There are some things though you could do to circumvent the problem of no user firing up the client anymore while there are still pending messages.

You could add a commandline utility (or commandline parameter as bepe4711 suggested) that will only check for pending messages and try to send them.

Add this commandline utility to the StartUp folder or Run key in the registry. This way messages will at least get sent when the computer restarts, even if the user does not fire up the your app.

Add a scheduled task to run this utility at least once every day. The scheduled task can be added by code or by your installer.

If you do both, you will only have to worry about pending messages of users that never start their computer again.

Marjan Venema
Thanks for completing bepe4711 answer.
A: 

If both Systems are running on Windows, have a look at MS Message Queue. It is designed to send notifications to systems, which are not allways online. I did it in .Net, there are already easy to use classes implemented. Not sure about Delphi.

max
+1  A: 

I do something very similar to the approach you describe. Instead of sending emails I need to call a web service. My application is installed on several laptops and they are commonly not connected to any network.

When my application raises an exception I collect various bits of information including user comments and screen shots. Then I attempt to send this to our web service. If by chance the web service is not available. (i.e. not connected to the internet or web service is down) I write the results to an XML file on disk in the User Profile (App_Data) directory.

The one major difference is I don't poll to check to see if the server is up. I attempt to send them again on the startup of the application.

Robert Love
Yes, I'd do something similar for sending buglogs/reports. In that case they message not getting sent because they never fire up the app again, isn't much of a problem. However, the OP asked for suggestion to avoid the limitation of being dependent upon the user starting up the app again.
Marjan Venema
@Robert the only problem I have is that the notification interest other users, so I cannot wait for the user to runt he application again, this may be will happen next week... Too late. I use the App_Data folder for all my temporary and user settings files, but inthis case it is not viable for me.
A: 

Latest version of Windows uses much more the Windows Task Scheduler, and now task can be fired on event (i.e. when a network card gets connected...). You could write a separate utility that tries to send pending notification, even if noone is logged in.

ldsandon
A separate utility or server is anyway a problem. I don't have this as an option now.