Hi guys I’m working on a feature to verify a user email using Accounts.emailTemplates. I use Accounts.templates.from to set the sender email, is there a way to set the reply to field of the email?
Hey, I don’t think so.
But there are packages integrated with other solutions that can provide that option for you.
Which provider are you using the send your emails?
Thanks, @filipenevola for the info. I’m using postmark for sending out emails. I’m wondering how I can integrate that into Accounts.emailTemplates. Any guidance or suggestion will be appreciated!
We are also using it in zcloud, see two snippets:
import { Email } from 'meteor/email';
import { sendRawEmail } from './sendRawEmail';
import { logger } from '../logger';
Email.customTransport = (options) => {
const { to, subject, html } = options;
const overrideOptions = Email.overrideOptionsBeforeSend
? Email.overrideOptionsBeforeSend(options)
: {};
sendRawEmail({
to,
subject,
content: html,
...overrideOptions,
})
.then(() => {
logger.log(`emailSetup:Email sent to ${to}`);
})
.catch((error) => {
logger.error(`emailSetup:Error sending email to ${to}`, error);
});
};
Accounts.emailTemplates = {
sendLoginToken: {
subject: (user, url, { sequence }) => {
// dont send login tokens in development by email
if (isDevelopment && !checkAllowSendEmail(user.email)) {
logger.info(
`===> In development we don't send login tokens by email (${user.emails[0].address}), here is your token: ${sequence}`
);
return null;
}
return `Access token for ${appNameWithEnv}: ${sequence}`;
},
html: (user, urlParam, { sequence }) =>
generateEmailHtml({
content: `
<mj-text padding="0 0 24px 0" color="#F8F7F7" font-size="24px" font-weight="400" align="left" line-height="30px">
Here’s the access token you requested
</mj-text>
<mj-section background-color="#2C2E2F" border-radius="8px">
<mj-column width="100%">
<mj-text color="#F8F7F7" padding="16px" font-size="48px" font-weight="400" align="center" line-height="52px">
${sequence}
</mj-text>
</mj-column>
</mj-section>
<mj-text padding="24px 0 24px 0" color="#F8F7F7" lign="left">
You’ll have to enter this token on the <a style="color: #B3FE71;" href="${appUrl}${RoutePaths.CONTINUE_WITH_EMAIL}?logIn=true">login page</a>
in the appropriate field.
</mj-text>
<mj-text padding="0 0 24px 0" align="left">
If you have any issues logging in our support team is always ready to help you out. Simply drop us an email
at <a style="color: #B3FE71;" href="mailto:support@zcloud.ws">support@zcloud.ws</a>, and we'll respond
within an hour during working hours.
</mj-text>
<mj-text padding="0 0 24px 0" align="left">
Feel free to also inquire about anything any time; we're here to assist you with everything from migration
to zCloud, Docker issues, or challenges with your custom stack.
</mj-text>
`,
appUrl,
}),
},
};
BTW, this is sendRawEmail code:
import { sendEmail } from 'meteor/quave:email-postmark';
import { EmailsCollection } from '../infra/EmailsCollection';
import { Random } from 'meteor/random';
export const sendRawEmail = async ({
to,
subject,
content,
from,
skipUniqueCheck,
}) => {
const recipients = typeof to === 'string' ? [to] : to;
const sends = recipients.map((email) => {
const shortDate = new Intl.DateTimeFormat('pt-BR', {
dateStyle: 'short',
}).format(new Date());
const uniqueKey = {
to,
subject,
shortDate: skipUniqueCheck ? `${Random.id()}-${shortDate}` : shortDate,
};
const emailId = EmailsCollection.save({
to: email,
subject,
content,
from,
...uniqueKey,
});
return sendEmail({ to: email, subject, content, from })
.then((responseData) => {
EmailsCollection.update(emailId, {
$set: {
updatedAt: new Date(),
sentAt: new Date(),
responseData,
},
});
})
.catch((e) => {
EmailsCollection.update(emailId, {
$set: {
updatedAt: new Date(),
errorAt: new Date(),
},
});
throw e;
});
});
return Promise.all(sends);
};
Of course, there are things there that you probably don’t care but I just shared the whole code.
Do you have specific questions?