I'm currently running an MVC website alongside a WebApi and I'm looking into building in the email functionality.
I have very lightweight controllers abstracting most of the logic away to a service layer as it's a fairly big application and I want to make most of it reusable between the MVC and the WebApi.
That's putting me off using MVCMailer because all the examples are running from within the web project. If a phone app was written which used the WebAPI it wouldn't be able to make use of the email functionality.
I'm wondering if it's possible to run it from it's own project? Here's a very crude depiction of what I'm trying to do.
MyProject.Web MyProject.WebApi
\ /
\ /
MyProject.Services
|
|
MyProject.Email
Can I abstract away either MVCMailer or ActionMailer as technically both the .Web
and .WebApi
are both MVC4 projects?
If not then I will just use the Standalone version of Actionmailer.net or the equivalent in Postal though the functionality is a bit cut down.
EDIT: More info
Thinking about it a bit more it seems like it would be tricky to do because I'd have to do some fancy copy logic for the email views so that they would deploy with both the mvc and the webapi website automatically.
Perhaps it would be better to separate the email to it's own website and have the services layer make web requests to send emails and properly abstract it away.
MyProject.Web MyProject.WebApi
\ /
\ /
MyProject.Services --http--> MyProject.Email
I guess that way I could just have the email deployed on one server rather than having to have smtp set up on all of them. Comments welcome
Related questions
As I mentioned in the question I created a separate email project which is essentially a bare bones webapi project.
MyProject.Web MyProject.WebApi
\ /
\ /
MyProject.Services --http--> MyProject.Email
I now send emails through a REST service to Email webapi.
Note:
I believe that this might be possible to do internally in the service layer using Razor Generator. You would create a MVC project called email but never run it directly, and include it in web project as a reference.
This would give you all the benefits of intellisense but you would compile the email views into code using the razor generator.
The downside to this approach is if you have multiple web servers you would have to have an smtp service installed on all of them.