Closed yashsaxena closed 3 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:
server/lib/template-sender
. It's a class, which has templateId
in the constructor and a send
async function, which takes an array of emails as a first argument and template params object as a second.
Short typing overview:
class TemplateSender {
templateId: string;
send(emails: string[], templateParams: Object) => Promise<void>
}
/templates/:templateId/send
route to templates.js
.@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.
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.
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.
Excellent. That would be perfect. Thanks. If you have any problem, just let me know. I'll be happy to help.
@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?
@alexeychikk - I'm afraid this is v1, I can help you only with v2.
I am looking for a transactional mails solution too.
@mikeslim7 you have to be more specific about your requirements. Mailtrain is not a general purpose transactional mail solution.
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.
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.
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?