Email translations
This commit is contained in:
parent
952431d296
commit
6c8fa91f64
30 changed files with 1844 additions and 107 deletions
|
|
@ -1,15 +1,24 @@
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { Email } from 'meteor/email';
|
||||
// import { Email } from 'meteor/email';
|
||||
import getPrivateFile from './get-private-file';
|
||||
import templateToText from './handlebars-email-to-text';
|
||||
import templateToHTML from './handlebars-email-to-html';
|
||||
import { getFileNameOfLang } from '/imports/api/Utility/server/files.js';
|
||||
import sendMail from '/imports/startup/server/email';
|
||||
import i18n from 'i18next';
|
||||
|
||||
const sendEmail = (options, { resolve, reject }) => {
|
||||
try {
|
||||
Meteor.defer(() => {
|
||||
// TODO: replace with import sendMail from '/imports/startup/server/email';
|
||||
console.log(`Email options: ${options}`);
|
||||
Email.send(options);
|
||||
// Meteor email options:
|
||||
// basic: from, to/cc/bcc/replyTo, subject, html, text,
|
||||
// others: watchHtml, icalEvent, headers, attachments, mailComposer, inReplyTo, references, messageId
|
||||
const opts = options;
|
||||
opts.template = '<body><h2>{{appName}}</h2>{{{html}}}</body>';
|
||||
opts.appName = i18n.t('AppName');
|
||||
// console.log(`Email options: ${JSON.stringify(opts)}`);
|
||||
sendMail(opts, true);
|
||||
// Email.send(options);
|
||||
resolve();
|
||||
});
|
||||
} catch (exception) {
|
||||
|
|
@ -18,14 +27,14 @@ const sendEmail = (options, { resolve, reject }) => {
|
|||
};
|
||||
|
||||
export default ({
|
||||
text, html, template, templateVars, ...rest
|
||||
text, html, lang, template, templateVars, ...rest
|
||||
}) => {
|
||||
if (text || html || template) {
|
||||
return new Promise((resolve, reject) => {
|
||||
sendEmail({
|
||||
...rest,
|
||||
text: template ? templateToText(getPrivateFile(`email-templates/${template}.txt`), (templateVars || {})) : text,
|
||||
html: template ? templateToHTML(getPrivateFile(`email-templates/${template}.html`), (templateVars || {})) : html
|
||||
text: template ? templateToText(getPrivateFile(getFileNameOfLang('email-templates', template, 'txt', lang)), (templateVars || {})) : text,
|
||||
html: template ? templateToHTML(getPrivateFile(getFileNameOfLang('email-templates', template, 'html', lang)), (templateVars || {})) : html
|
||||
}, { resolve, reject });
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue