mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
dont wait for emails
This commit is contained in:
parent
dd86e51121
commit
c6369d1e0b
@ -16,13 +16,16 @@ export const sendEmailTranslated = async (params: {
|
|||||||
}
|
}
|
||||||
template: string
|
template: string
|
||||||
locals: Record<string, unknown>
|
locals: Record<string, unknown>
|
||||||
}): Promise<Record<string, unknown> | null> => {
|
}): Promise<Boolean | null> => {
|
||||||
let resultSend: Record<string, unknown> | null = null
|
|
||||||
|
|
||||||
// TODO: test the calling order of 'i18n.setLocale' for example: language of logging 'en', language of email receiver 'es', reset language of current user 'de'
|
// TODO: test the calling order of 'i18n.setLocale' for example: language of logging 'en', language of email receiver 'es', reset language of current user 'de'
|
||||||
|
|
||||||
|
if (!CONFIG.EMAIL) {
|
||||||
|
logger.info(`Emails are disabled via config...`)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
// because language of receiver can differ from language of current user who triggers the sending
|
// because language of receiver can differ from language of current user who triggers the sending
|
||||||
const rememberLocaleToRestore = i18n.getLocale()
|
// const rememberLocaleToRestore = i18n.getLocale()
|
||||||
|
|
||||||
i18n.setLocale('en') // for logging
|
i18n.setLocale('en') // for logging
|
||||||
logger.info(
|
logger.info(
|
||||||
@ -31,10 +34,6 @@ export const sendEmailTranslated = async (params: {
|
|||||||
`, subject=${i18n.__('emails.' + params.template + '.subject')}`,
|
`, subject=${i18n.__('emails.' + params.template + '.subject')}`,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!CONFIG.EMAIL) {
|
|
||||||
logger.info(`Emails are disabled via config...`)
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
if (CONFIG.EMAIL_TEST_MODUS) {
|
if (CONFIG.EMAIL_TEST_MODUS) {
|
||||||
logger.info(
|
logger.info(
|
||||||
`Testmodus=ON: change receiver from ${params.receiver.to} to ${CONFIG.EMAIL_TEST_RECEIVER}`,
|
`Testmodus=ON: change receiver from ${params.receiver.to} to ${CONFIG.EMAIL_TEST_RECEIVER}`,
|
||||||
@ -43,7 +42,7 @@ export const sendEmailTranslated = async (params: {
|
|||||||
}
|
}
|
||||||
const transport = createTransport({
|
const transport = createTransport({
|
||||||
host: CONFIG.EMAIL_SMTP_URL,
|
host: CONFIG.EMAIL_SMTP_URL,
|
||||||
port: Number(CONFIG.EMAIL_SMTP_PORT),
|
port: CONFIG.EMAIL_SMTP_PORT,
|
||||||
secure: false, // true for 465, false for other ports
|
secure: false, // true for 465, false for other ports
|
||||||
requireTLS: CONFIG.EMAIL_TLS,
|
requireTLS: CONFIG.EMAIL_TLS,
|
||||||
auth: {
|
auth: {
|
||||||
@ -64,23 +63,16 @@ export const sendEmailTranslated = async (params: {
|
|||||||
// i18n, // is only needed if you don't install i18n
|
// i18n, // is only needed if you don't install i18n
|
||||||
})
|
})
|
||||||
|
|
||||||
// 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
|
void email
|
||||||
await email
|
|
||||||
.send({
|
.send({
|
||||||
template: path.join(__dirname, 'templates', params.template),
|
template: path.join(__dirname, 'templates', params.template),
|
||||||
message: params.receiver,
|
message: params.receiver,
|
||||||
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'
|
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: Record<string, unknown>) => {
|
|
||||||
resultSend = result
|
|
||||||
logger.info('Send email successfully !!!')
|
|
||||||
logger.info('Result: ', result)
|
|
||||||
})
|
|
||||||
.catch((error: unknown) => {
|
.catch((error: unknown) => {
|
||||||
throw new LogError('Error sending notification email', error)
|
new LogError('Error sending notification email', error)
|
||||||
|
return false;
|
||||||
})
|
})
|
||||||
|
|
||||||
i18n.setLocale(rememberLocaleToRestore)
|
return true;
|
||||||
|
|
||||||
return resultSend
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -146,7 +146,7 @@ export class ContributionMessageResolver {
|
|||||||
await queryRunner.manager.update(DbContribution, { id: contributionId }, contribution)
|
await queryRunner.manager.update(DbContribution, { id: contributionId }, contribution)
|
||||||
}
|
}
|
||||||
|
|
||||||
await sendAddedContributionMessageEmail({
|
void sendAddedContributionMessageEmail({
|
||||||
firstName: contribution.user.firstName,
|
firstName: contribution.user.firstName,
|
||||||
lastName: contribution.user.lastName,
|
lastName: contribution.user.lastName,
|
||||||
email: contribution.user.emailContact.email,
|
email: contribution.user.emailContact.email,
|
||||||
|
|||||||
@ -149,7 +149,7 @@ export const executeTransaction = async (
|
|||||||
} finally {
|
} finally {
|
||||||
await queryRunner.release()
|
await queryRunner.release()
|
||||||
}
|
}
|
||||||
await sendTransactionReceivedEmail({
|
void sendTransactionReceivedEmail({
|
||||||
firstName: recipient.firstName,
|
firstName: recipient.firstName,
|
||||||
lastName: recipient.lastName,
|
lastName: recipient.lastName,
|
||||||
email: recipient.emailContact.email,
|
email: recipient.emailContact.email,
|
||||||
@ -160,7 +160,7 @@ export const executeTransaction = async (
|
|||||||
transactionAmount: amount,
|
transactionAmount: amount,
|
||||||
})
|
})
|
||||||
if (transactionLink) {
|
if (transactionLink) {
|
||||||
await sendTransactionLinkRedeemedEmail({
|
void sendTransactionLinkRedeemedEmail({
|
||||||
firstName: sender.firstName,
|
firstName: sender.firstName,
|
||||||
lastName: sender.lastName,
|
lastName: sender.lastName,
|
||||||
email: sender.emailContact.email,
|
email: sender.emailContact.email,
|
||||||
|
|||||||
@ -245,7 +245,7 @@ export class UserResolver {
|
|||||||
user.publisherId = publisherId
|
user.publisherId = publisherId
|
||||||
logger.debug('partly faked user', user)
|
logger.debug('partly faked user', user)
|
||||||
|
|
||||||
const emailSent = await sendAccountMultiRegistrationEmail({
|
void sendAccountMultiRegistrationEmail({
|
||||||
firstName: foundUser.firstName, // this is the real name of the email owner, but just "firstName" would be the name of the new registrant which shall not be passed to the outside
|
firstName: foundUser.firstName, // this is the real name of the email owner, but just "firstName" would be the name of the new registrant which shall not be passed to the outside
|
||||||
lastName: foundUser.lastName, // this is the real name of the email owner, but just "lastName" would be the name of the new registrant which shall not be passed to the outside
|
lastName: foundUser.lastName, // this is the real name of the email owner, but just "lastName" would be the name of the new registrant which shall not be passed to the outside
|
||||||
email,
|
email,
|
||||||
@ -258,9 +258,6 @@ export class UserResolver {
|
|||||||
)
|
)
|
||||||
/* uncomment this, when you need the activation link on the console */
|
/* uncomment this, when you need the activation link on the console */
|
||||||
// In case EMails are disabled log the activation link for the user
|
// In case EMails are disabled log the activation link for the user
|
||||||
if (!emailSent) {
|
|
||||||
logger.debug(`Email not send!`)
|
|
||||||
}
|
|
||||||
logger.info('createUser() faked and send multi registration mail...')
|
logger.info('createUser() faked and send multi registration mail...')
|
||||||
|
|
||||||
return user
|
return user
|
||||||
@ -325,8 +322,7 @@ export class UserResolver {
|
|||||||
emailContact.emailVerificationCode.toString(),
|
emailContact.emailVerificationCode.toString(),
|
||||||
).replace(/{code}/g, redeemCode ? '/' + redeemCode : '')
|
).replace(/{code}/g, redeemCode ? '/' + redeemCode : '')
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
void sendAccountActivationEmail({
|
||||||
const emailSent = await sendAccountActivationEmail({
|
|
||||||
firstName,
|
firstName,
|
||||||
lastName,
|
lastName,
|
||||||
email,
|
email,
|
||||||
@ -338,10 +334,6 @@ export class UserResolver {
|
|||||||
|
|
||||||
await EVENT_EMAIL_CONFIRMATION(dbUser)
|
await EVENT_EMAIL_CONFIRMATION(dbUser)
|
||||||
|
|
||||||
if (!emailSent) {
|
|
||||||
logger.debug(`Account confirmation link: ${activationLink}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
await queryRunner.commitTransaction()
|
await queryRunner.commitTransaction()
|
||||||
logger.addContext('user', dbUser.id)
|
logger.addContext('user', dbUser.id)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -392,8 +384,8 @@ export class UserResolver {
|
|||||||
})
|
})
|
||||||
|
|
||||||
logger.info(`optInCode for ${email}=${user.emailContact}`)
|
logger.info(`optInCode for ${email}=${user.emailContact}`)
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
const emailSent = await sendResetPasswordEmail({
|
void sendResetPasswordEmail({
|
||||||
firstName: user.firstName,
|
firstName: user.firstName,
|
||||||
lastName: user.lastName,
|
lastName: user.lastName,
|
||||||
email,
|
email,
|
||||||
@ -402,13 +394,6 @@ export class UserResolver {
|
|||||||
timeDurationObject: getTimeDurationObject(CONFIG.EMAIL_CODE_VALID_TIME),
|
timeDurationObject: getTimeDurationObject(CONFIG.EMAIL_CODE_VALID_TIME),
|
||||||
})
|
})
|
||||||
|
|
||||||
/* uncomment this, when you need the activation link on the console */
|
|
||||||
// In case EMails are disabled log the activation link for the user
|
|
||||||
if (!emailSent) {
|
|
||||||
logger.debug(
|
|
||||||
`Reset password link: ${activationLink(user.emailContact.emailVerificationCode)}`,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
logger.info(`forgotPassword(${email}) successful...`)
|
logger.info(`forgotPassword(${email}) successful...`)
|
||||||
await EVENT_EMAIL_FORGOT_PASSWORD(user)
|
await EVENT_EMAIL_FORGOT_PASSWORD(user)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user