From where to send mails in a MVC framework, so that there is no duplication of code?

Posted by Sabya on Stack Overflow See other posts from Stack Overflow or by Sabya
Published on 2010-05-10T09:40:38Z Indexed on 2010/05/10 9:44 UTC
Read the original article Hit count: 272

Filed under:
|
|

It's a MVC question. Here is the situation:

  1. I am writing an application where I have "groups".
  2. You can invite other persons to your groups by typing their email and clicking "invite".
  3. There are two ways this functionality can be called: a) web interface and b) API
  4. After the mail sending is over I want to report to the user which mails were sent successfully (i.e., if the SMTP send succeeded. Currently, I am not interested in reporting mail bounces).

So, I am thinking how should I design so that there is no code duplication. That is, API and web-interface should share the bulk of the code.

To do this, I can create the method "invite" inside the model "group". So, the API and and the Web-interface can just call: group->invite($emailList); This method can send the emails. But the, problem is, then I have to access the mail templates, create the views for the mails, and then send the mails. Which should actually be in the "View" part or at least in the "Controller" part.

What is the most elegant design in this situation?

Note: I am really thinking to write this in the Model. My only doubt is: previously I thought sending mails also as "presentation". Since it is may be considered as a different form of generating output.

© Stack Overflow or respective owner

Related posts about mvc

Related posts about kohana