API: Add env var to opt-out mailer setup verification (#13924)

* Add env var to opt-out mailer setup verification

* Add documentation
This commit is contained in:
José Varela
2022-06-16 14:15:23 +01:00
committed by GitHub
parent 9898175f28
commit 0f438ef3d0
3 changed files with 32 additions and 27 deletions

View File

@@ -137,6 +137,7 @@ const allowedEnvironmentVars = [
// emails
'EMAIL_FROM',
'EMAIL_TRANSPORT',
'EMAIL_VERIFY_SETUP',
'EMAIL_SENDMAIL_NEW_LINE',
'EMAIL_SENDMAIL_PATH',
'EMAIL_SMTP_HOST',
@@ -217,6 +218,7 @@ const defaults: Record<string, any> = {
EXTENSIONS_AUTO_RELOAD: false,
EMAIL_FROM: 'no-reply@directus.io',
EMAIL_VERIFY_SETUP: true,
EMAIL_TRANSPORT: 'sendmail',
EMAIL_SENDMAIL_NEW_LINE: 'unix',
EMAIL_SENDMAIL_PATH: '/usr/sbin/sendmail',

View File

@@ -36,12 +36,14 @@ export class MailService {
this.knex = opts?.knex || getDatabase();
this.mailer = getMailer();
this.mailer.verify((error) => {
if (error) {
logger.warn(`Email connection failed:`);
logger.warn(error);
}
});
if (env.EMAIL_VERIFY_SETUP) {
this.mailer.verify((error) => {
if (error) {
logger.warn(`Email connection failed:`);
logger.warn(error);
}
});
}
}
async send(options: EmailOptions): Promise<void> {