Got a fairly large web application in asp.net using C#. Also have a mobile setup using a common api that we wrote to basically share data across both of our apps using web methods and common classes.
Email was initially thrown together in maybe two days using a simple email class and some basic properties.
For instance, once a record is created we send an email. Imagine a crm type system such that when an account or a customer is created an email is sent. The thing I dislike the most is we're calling it right from within for instance the presentation layer:
MyAPI.SaveCompany(company object);
Email.SendMail(...);
For the mobile application we've got a web service to for instance save a company just like above. Then just as shown above after saving a company we do the same thing Email.SendMail
right within the web method.
Its time to fix this as to me it just feels wrong. What do you guys recommend I do?
Should this be a standalone service that sends emails based on events in a database table that keeps track of all these events,
Or should I just create an email class like I already have and just call it somewhere else?
I thought about just calling it right when I call SaveCompany
(inside this method) and then I wouldn't have to worry about my web UI or my mobile since its inside SaveCompany
it would call it automatically. But then this feels wrong as it ties up my manager class (my API) to some physical email implementation.
Can someone please give me some hints or how they accomplish this possibly a look at their design or thought process.
As mentioned this is ASP.NET Web Forms, C#, a lot of jQuery, and SQL Server 2008.