Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does sending an email belong in the presentation layer or business layer of an application?

I am trying to figure out the best area to place code to send an email in my Asp.net MVC application. Right now my application is setup in 2 VS projects separating out the business layer from the presentation layer. I am trying to setup a situation that when a user reset's their password, after the business logic changes the password the server will send an email to the user with their newly generated password.

Should I be calling the code to send the email (including data on how the email looks) from the business layer (after the business layer resets the password) or in the presentation layer (after the business layer returns a successful result)?

like image 247
KallDrexx Avatar asked Apr 20 '11 21:04

KallDrexx


1 Answers

Sending emails should be part of the business layer.

I came across the same issue few weeks ago ,,, I am building a web application using asp.net mvc 3 that consists of three projects : Repository (DAL), Services (BLL) , Presentation (Web)

My application logic is implemented at the service layer so I was searching for the best way to implement a completely independent module at the service layer for sending HTML emails to the users so that that my service layer functions can use it directly without having to bring it up to the presentation layer.

After some searching I found an elegant solution that was done by Kazi Manzur where he created an email subsystem that makes use of Razor Views to send HTML/Text emails outside of the web proejct.

Use Razor for Email Template outside ASP.NET MVC

I have been using his subsystem since then and it has been doing a great job.

like image 194
Manaf Abu.Rous Avatar answered Sep 20 '22 18:09

Manaf Abu.Rous