Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodemailer #101

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ JWT_VERIFY_EMAIL_EXPIRATION_MINUTES=10
# For testing, you can use a fake SMTP service like Ethereal: https://ethereal.email/create
SMTP_HOST=email-server
SMTP_PORT=587
# SMTP_SECURE Use TLS or upgrade later with STARTTLS
SMTP_SECURE=false
trasherdk marked this conversation as resolved.
Show resolved Hide resolved
SMTP_REJECT_SELFSIGNED_CERTS=false
SMTP_USERNAME=email-server-username
SMTP_PASSWORD=email-server-password
EMAIL_FROM=support@yourapp.com
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ yarn-error.log

# Code coverage
coverage
.husky/_
6 changes: 6 additions & 0 deletions src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const envVarsSchema = Joi.object()
.description('minutes after which verify email token expires'),
SMTP_HOST: Joi.string().description('server that will send the emails'),
SMTP_PORT: Joi.number().description('port to connect to the email server'),
SMTP_SECURE: Joi.boolean().description('Use TLS or upgrade later with STARTTLS'),
SMTP_REJECT_SELFSIGNED_CERTS: Joi.boolean().description('Accept or Reject self-signed certificates.'),
SMTP_USERNAME: Joi.string().description('username for email server'),
SMTP_PASSWORD: Joi.string().description('password for email server'),
EMAIL_FROM: Joi.string().description('the from field in the emails sent by the app'),
Expand Down Expand Up @@ -54,10 +56,14 @@ module.exports = {
smtp: {
host: envVars.SMTP_HOST,
port: envVars.SMTP_PORT,
secure: envVars.SMTP_SECURE,
auth: {
user: envVars.SMTP_USERNAME,
pass: envVars.SMTP_PASSWORD,
},
tls: {
rejectUnauthorized: envVars.SMTP_REJECT_SELFSIGNED_CERTS,
},
},
from: envVars.EMAIL_FROM,
},
Expand Down
10 changes: 8 additions & 2 deletions src/services/email.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ const transport = nodemailer.createTransport(config.email.smtp);
if (config.env !== 'test') {
transport
.verify()
.then(() => logger.info('Connected to email server'))
.catch(() => logger.warn('Unable to connect to email server. Make sure you have configured the SMTP options in .env'));
.then(() => {
logger.info(`Email transport verify successful`);
})
.catch((error) => {
logger.warn(`Email transport verify returned: ${error}`);
logger.warn(`Unable to make connection to ${config.email.smtp.host}:${config.email.smtp.port}`);
logger.warn('Make sure you have configured the SMTP options in .env');
});
}

/**
Expand Down