diff --git a/Dockerfile b/Dockerfile index 4c47e737f6b1d580e2827c7981cff9cdbbf0d9c4..59882c3c7c162e17f374f52bd4b493350b5854b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:12.13-slim +FROM node:14-slim # Create app directory WORKDIR /app 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..d32d55355875b4d957672e068c21ff10223a3c41 100644 --- a/src/configuration/config.service.ts +++ b/src/configuration/config.service.ts @@ -9,16 +9,30 @@ 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; + this._config.smtpConfig.auth.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; } get config() { + const filteredConf = { ...this._config }; + + if ( + !this._config.smtpConfig.auth.user && + !this._config.smtpConfig.auth.pass + ) { + delete this._config.smtpConfig.auth; + } return this._config; } -} \ No newline at end of file +} diff --git a/src/configuration/config.ts b/src/configuration/config.ts index 69f00c4021937eb347338a8f3e537ea7bbb87ad9..661a9234b6f2250d7d9ad7664e79898ea68af2a5 100644 --- a/src/configuration/config.ts +++ b/src/configuration/config.ts @@ -7,10 +7,10 @@ export const config = { // do not fail on invalid certs rejectUnauthorized: false, }, - // auth: { - // user: process.env.SMTP_USER, - // pass: process.env.SMTP_PASS - // } + auth: { + user: null, + pass: null, + }, }, userSupportMailbox: '', imageHost: '', @@ -21,4 +21,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>