Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email sending strategy with C#/.NET

I have a web application from which emails should be sent after specific actions. I have some alternatives for handling this I'm not sure which one is the best.

The first is that, when a user does an action the email is being sent directly from the ASP.NET application. But I think this is not a really reliable system because if the SMTP server is down or something else happens, the user just gets a feedback that his action cannot be completed.

As an alternative I was thinking about implementing a queuing system for what I have some ideas:

  • Push emails to send, into a database table, and a service application periodically checks for new messages, then sends them. On successful send it marks the email task completed.
  • Use MSMQ for queing. In this case the whole email could be passed as a message; or the other way is to store the message with attachments into a db table, and pass only the data which is required to query the db table and send the message. In this case I don't have to deal with size limits of MSMQ (because of attachments).
  • something else, like a local WCF service to notify the service

Which way you think is the best?

like image 989
norbip Avatar asked Oct 10 '22 19:10

norbip


1 Answers

Use MSMQ is not good solution since has a limitation of 4 MB of each size. http://blogs.msdn.com/b/johnbreakwell/archive/2007/08/22/why-is-there-a-4mb-limit-on-msmq-messages.aspx Worse case scenario, if MSMQ is failed like it process throw error or suddenly shutdown, it will loss many message. In my case, this solution is good when hardware and software is instaled in almost ideal

Use database and window service is better since it is a simple and doesn't need much effort.

I usually use a combination of database and file. The database contains table to save a header information and a flag that message has been action (either success or error or else) and files contains message (either html or plain) and attachment in original format. When process is run to send, it is quicker to assemble a message from files rather than from querying blob/clob. Since they are using file system on the application, you can add hardware like server or components or else to add availibility of the system easily. Database can be added too, but it will cost you more license in databse software. I add a test send email after send email in x times to make sure it is works well; this test email is send to my self or dummy inbox and an application to check the test email that is the same email that send and receive. If it is the same, sending pending email will continue again

Another way if you are using MS Exchange, you can use message queue by utilize its web service to queue send. This is an easy way but you need license. You can see on MSDN library how to utilize MS Exchange web service.

like image 168
nickotech2000 Avatar answered Oct 19 '22 07:10

nickotech2000