Mailtrain-org / mailtrain

Self hosted newsletter app
GNU General Public License v3.0
5.52k stars 692 forks source link

How to send transactional mails through mailtrain #352

Closed yashsaxena closed 3 years ago

yashsaxena commented 6 years ago

Is there a way to send transactional mails through mailtrain? But since transactional mails will not belong to any campaign & list will have a single email - how would that be triggered with mailtrain? I'm okay if there is a pure API way to fire this.

Additionally if this functionality needs to be built into mailtrain - how extensive is the effort?

goooseman commented 5 years ago

We were looking for a solution for sending emails, we've tried mailtrain v2 and it is really excellent for us.

The only usecase we are missing is transactional mails.

I can add this functionality, but I need a little help with implementation details.

I've did a quick look at v2 source code and here is my first plan:

@bures what do you think? If this feature is OK for you and for v2 release, I will be happy to make a PR with this feature.

bures commented 5 years ago

Sounds like a good plan to me. I'll be very happy to merge this PR. Thanks.

As for the POST, if you want to use this as API (i.e. authenticated via access token), it would be better to put it to api.js (rather than in routes/templates.js).

I assume that the number of emails send via a single call (i.e. the emails array in TemplateSender.send) will be relatively small, right? My guess, it won't really scale above tens or hundreds of addresses. Should the number be bigger, you would likely also need some asynchronous sending process and there we would get very close to campaigns functionality.

goooseman commented 5 years ago

Yep, I want it to call with an access token.

In our usecase the number of emails will be always one.

I can make a restriction, so this API endpoint will not accept more than 100 addresses, so we will not have problems with asynchronous sending.

bures commented 5 years ago

Excellent. That would be perfect. Thanks. If you have any problem, just let me know. I'll be happy to help.

alexeychikk commented 5 years ago

@bures Hi! I'm trying to implement what's discussed above and I have a question: I retrieve template by id using lib/models/templates like this: templates.get(templateId, (err, template) => { /*...*/ }).
Then I use lib/mailer to send the template like this:

mailer.sendMail(
   { 
     from: { address: settings.adminEmail },
     to: { address: email },
     subject: input.SUBJECT
   },
   {
     html: template.html, // using template.html from db
     text: template.text, // using template.text from db
     data: input.DATA
   },
   err => { /*...*/ }
);

BUT mailer tries to load template from file system that causes error. Is there some argument that avoids loading template from FS or maybe there is a better way to do what I want?

bures commented 5 years ago

@alexeychikk - I'm afraid this is v1, I can help you only with v2.

mikeslim7 commented 5 years ago

I am looking for a transactional mails solution too.

bures commented 5 years ago

@mikeslim7 you have to be more specific about your requirements. Mailtrain is not a general purpose transactional mail solution.

mikeslim7 commented 5 years ago

I wanted to know If I can use mailtrain to send transactional emails such as password reset emails. Therefore I can be able to manage the email template on mailgun and trigger the email to a specific person through API rather than a mailing list.

bharatkashyap commented 4 years ago

Hello Mailtrain community! Using Mailtrain v2 for Campaign as well as Transactional emails. The issue is that Mailtrain does not provide any tracking support for Transactional emails; looking for guidance over how to implement this.