mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Refine 'sendEmailTranslated.ts'
This commit is contained in:
parent
5fcd684b6b
commit
e1392b0483
@ -29,9 +29,6 @@ export const sendEmailTranslated = async (params: {
|
|||||||
`, subject=${i18n.__('emails.' + params.template + '.subject')}`,
|
`, subject=${i18n.__('emails.' + params.template + '.subject')}`,
|
||||||
)
|
)
|
||||||
|
|
||||||
i18n.setLocale(params.locals.locale) // for email
|
|
||||||
// Wolle:
|
|
||||||
// console.log('sendEmailTranslated – i18n.getLocale, email: ', i18n.getLocale())
|
|
||||||
if (!CONFIG.EMAIL) {
|
if (!CONFIG.EMAIL) {
|
||||||
logger.info(`Emails are disabled via config...`)
|
logger.info(`Emails are disabled via config...`)
|
||||||
return false
|
return false
|
||||||
@ -53,15 +50,16 @@ export const sendEmailTranslated = async (params: {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
i18n.setLocale(params.locals.locale) // for email
|
||||||
|
// Wolle:
|
||||||
|
// console.log('sendEmailTranslated – i18n.getLocale, email: ', i18n.getLocale())
|
||||||
|
|
||||||
const email = new Email({
|
const email = new Email({
|
||||||
message: {
|
message: {
|
||||||
from: `Gradido (nicht antworten) <${CONFIG.EMAIL_SENDER}>`,
|
from: `Gradido (nicht antworten) <${CONFIG.EMAIL_SENDER}>`,
|
||||||
},
|
},
|
||||||
// uncomment below to send emails in development/test env:
|
// uncomment below to send emails in development/test env:
|
||||||
// send: true,
|
// send: true,
|
||||||
// transport: {
|
|
||||||
// jsonTransport: true,
|
|
||||||
// },
|
|
||||||
transport,
|
transport,
|
||||||
// uncomment below to open send emails in the browser
|
// uncomment below to open send emails in the browser
|
||||||
// preview: {
|
// preview: {
|
||||||
@ -70,16 +68,17 @@ export const sendEmailTranslated = async (params: {
|
|||||||
// wait: false,
|
// wait: false,
|
||||||
// },
|
// },
|
||||||
// },
|
// },
|
||||||
|
// Wolle
|
||||||
// i18n, // is only needed if you don't install i18n
|
// i18n, // is only needed if you don't install i18n
|
||||||
})
|
})
|
||||||
|
|
||||||
// TESTING: to send emails to yourself set .env "EMAIL_TEST_MODUS=true" and "EMAIL_TEST_RECEIVER" to your preferred email address
|
// TESTING: see 'README.md'
|
||||||
// ATTENTION: await is needed, because otherwise on send the email gets send in the language from the current user, because below the language gets reset to the current user
|
// ATTENTION: await is needed, because otherwise on send the email gets send in the language of the current user, because below the language gets reset
|
||||||
await email
|
await email
|
||||||
.send({
|
.send({
|
||||||
template: path.join(__dirname, params.template),
|
template: path.join(__dirname, params.template),
|
||||||
message: params.receiver,
|
message: params.receiver,
|
||||||
locals: params.locals,
|
locals: params.locals, // the 'locale' in here seems not to be used by 'email-template', because it doesn't work if the language isn't set before by 'i18n.setLocale'
|
||||||
})
|
})
|
||||||
.then((result: unknown) => {
|
.then((result: unknown) => {
|
||||||
logger.info('Send email successfully !!!')
|
logger.info('Send email successfully !!!')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user