diff --git a/docker-compose.yml b/docker-compose.yml index 761adf705b27f7a13c272d9ce356cf53a47de542..3ce9f628d58648fd63d6ec8a59e00517bc660f51 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,6 @@ -version: "3.1" +version: '3.1' services: - mail-service: build: . image: registry.forge.grandlyon.com/web-et-numerique/web-et-numerique-internet/data.grandlyon.com/web-portal/components/services/mailer:${TAG} @@ -10,6 +9,8 @@ services: environment: - SMTP_HOST=${SMTP_HOST} - SMTP_PORT=${SMTP_PORT} + - SMTP_USER=${SMTP_USER} + - SMTP_PASSWORD=${SMTP_PASSWORD} - MAIL_SUBJECT_PREFIX=${MAIL_SUBJECT_PREFIX} - USER_SUPPORT_MAILBOX=${USER_SUPPORT_MAILBOX} - NO_REPLY_MAIL_ADDRESS=${NO_REPLY_MAIL_ADDRESS} @@ -17,4 +18,4 @@ services: - GROUP_HEADER=x-consumer-groups - EMAIL_WRITER_GROUP_NAME=email-writer - IMAGE_HOST=https://minio.alpha.grandlyon.com/email-template-assets - restart: unless-stopped \ No newline at end of file + restart: unless-stopped diff --git a/src/configuration/config.service.ts b/src/configuration/config.service.ts index 6fa1dfd05f1e37050b025b0e1cfde2b0a0c6c60f..9651408b6d3e8465464ce8048dcc84ca0441cc2f 100644 --- a/src/configuration/config.service.ts +++ b/src/configuration/config.service.ts @@ -9,10 +9,18 @@ export class ConfigService { // Initializing conf with values from var env this._config.smtpConfig.host = process.env.SMTP_HOST; this._config.smtpConfig.port = process.env.SMTP_PORT; + + if (process.env.SMTP_USER && process.env.SMTP_PASSWORD) { + this._config.smtpConfig.auth = { + user: process.env.SMTP_USER, + pass: process.env.SMTP_PASSWORD, + }; + } this._config.mailSubjectPrefix = process.env.MAIL_SUBJECT_PREFIX; this._config.userSupportMailbox = process.env.USER_SUPPORT_MAILBOX; this._config.noReplyMailAddress = process.env.NO_REPLY_MAIL_ADDRESS; - this._config.additionalFeedbackEmails = process.env.ADDITIONAL_FEEDBACK_EMAILS; + this._config.additionalFeedbackEmails = + process.env.ADDITIONAL_FEEDBACK_EMAILS; this._config.groupHeader = process.env.GROUP_HEADER; this._config.groupNames.emailWriter = process.env.EMAIL_WRITER_GROUP_NAME; this._config.imageHost = process.env.IMAGE_HOST; @@ -21,4 +29,4 @@ export class ConfigService { get config() { return this._config; } -} \ No newline at end of file +} diff --git a/src/configuration/config.ts b/src/configuration/config.ts index 69f00c4021937eb347338a8f3e537ea7bbb87ad9..756ec28a60a2ad17c43889c6eb41e6a25705fa77 100644 --- a/src/configuration/config.ts +++ b/src/configuration/config.ts @@ -7,10 +7,6 @@ export const config = { // do not fail on invalid certs rejectUnauthorized: false, }, - // auth: { - // user: process.env.SMTP_USER, - // pass: process.env.SMTP_PASS - // } }, userSupportMailbox: '', imageHost: '', @@ -21,4 +17,4 @@ export const config = { mailSubjectPrefix: '', noReplyMailAddress: '', additionalFeedbackEmails: '', -}; \ No newline at end of file +}; diff --git a/template.env b/template.env index 64c25e5ff5f6b4c9ca9c0615327b3549a64b66ce..91493760f3a7168609cd22750ec32d65dd02bd5b 100644 --- a/template.env +++ b/template.env @@ -2,6 +2,8 @@ TAG=<version of the service to deploy> SMTP_HOST=<host of the SMTP server> SMTP_PORT=<port of the SMTP server> +SMTP_USER=<username of the SMTP server> +SMTP_PASSWORD=<password for the user of the SMTP server> MAIL_SERVICE_BIND_PORT=<listening port of the service> MAIL_SUBJECT_PREFIX=<prefix used in email subject>