molosc
July 23, 2016, 2:12am
1
Hi everybody.
I’m looking for the attachments options to send the verifyEmail of Accounts package.
Something like this:
Accounts.emailTemplates.verifyEmail.attachments = [{
fileName: ‘logo.jpg’,
filePath: “/email/logo.jpg”,
cid: cidLogo,
contentType: ‘image/jpeg’,
}];
It seem to be not available yet, I’m right ?
Is there another way to attach an image in the verifyEmail / resetPassword etc ?
Thank you so much!
molosc
July 24, 2016, 12:42am
2
I try add an attachment with the sendVerificationEmail Accounts function, from the onCreateUser Accounts event, but it’s not working either.
Nobody have an idea to do this?
This is an old thread, but I had exact same question. I wanted to send an email with my company logo embedded. After examining the code I realized this feature is not supported, but can be easily added by defning this function that should override the original one in accounts-password package:
Accounts.generateOptionsForEmail = (email, user, url, reason) => {
const options = {
to: email,
from: Accounts.emailTemplates[reason].from
? Accounts.emailTemplates[reason].from(user)
: Accounts.emailTemplates.from,
subject: Accounts.emailTemplates[reason].subject(user)
};
if (typeof Accounts.emailTemplates[reason].text === 'function') {
options.text = Accounts.emailTemplates[reason].text(user, url);
}
if (typeof Accounts.emailTemplates[reason].html === 'function') {
options.html = Accounts.emailTemplates[reason].html(user, url);
}
if (typeof Accounts.emailTemplates[reason].attachments === 'function') {
options.attachments = Accounts.emailTemplates[reason].attachments();
}
if (typeof Accounts.emailTemplates.headers === 'object') {
options.headers = Accounts.emailTemplates.headers;
}
return options;
};
This is the line that I added to the original function:
if (typeof Accounts.emailTemplates[reason].attachments === "function") {
options.attachments = Accounts.emailTemplates[reason].attachments();
}
Then you can attach files like this:
Accounts.emailTemplates.verifyEmail = {
subject() {
...
},
html(user, url) {
...
},
attachments() {
return [{
filename: "logo.png",
content: Assets.getBinary("emails/img/logo.png"),
contentType: "image/png",
cid: "logo-png"
}];
}
};
3 Likes
molosc
November 24, 2019, 3:50pm
4
It’s beautiful ! Thank you so much