tags:

views:

23

answers:

1

In a MVC web application, I often send emails.

I usually do it in the controller, as I load all my views from the controller (including email views).

Now, however, I have some code where the email sends from the model.

Which tier is email generally sent from? Does it matter? Does it need to be consistent?

+1  A: 

A controller should ideally be like an operator that connects a view to a model. This either belongs in the model or service layer.

I would argue that this belongs in the Model layer only if you have a model object that is solely responsible for sending e-mails. You don't want to comingle presentation and logic, that's the whole point of separation of concerns in Model-View-Controller.

This type of logic should reside in a service layer. You could then use dependency injection to inject the service into the controller and call EmailSenderService.sendEmail();

Visionary Software Solutions