From c61edbff214f81956d5be7b4a36309374415bb9a Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sat, 17 Oct 2020 08:45:41 +0200 Subject: [PATCH] replaced nodemailer with @sendgrid/mail --- lib/email/mailer.js | 25 +++++-------------------- package.json | 2 +- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/lib/email/mailer.js b/lib/email/mailer.js index 4885c62..8e5d96d 100644 --- a/lib/email/mailer.js +++ b/lib/email/mailer.js @@ -2,7 +2,8 @@ const fs = require('fs'); const pug = require('pug'); -const nodemailer = require('nodemailer'); +const sendgrid = require('@sendgrid/mail'); + const texttemplate = fs.readFileSync(__dirname + '/template.txt', 'utf-8'); /** @@ -19,24 +20,14 @@ const plaintextMessage = function(token) { return texttemplate.replace(//, token); }; -/** - * Create a reusable transport method. - */ - -const transport = nodemailer.createTransport({ - service: 'SendGrid', - auth: { - user: process.env.SENDGRID_USER, - pass: process.env.SENDGRID_PASS - } -}); +sendgrid.setApiKey(process.env.SENDGRID_API_KEY); /** * Send the reset password email. */ exports.sendEmail = function(to, token, callback) { - transport.sendMail( + sendgrid.send( { from: 'binb ', to: to, @@ -44,12 +35,6 @@ exports.sendEmail = function(to, token, callback) { html: HTMLMessage({ token: token }), text: plaintextMessage(token) }, - function(err, info) { - if (err) { - return callback(err); - } - - callback(null, info); - } + callback ); }; diff --git a/package.json b/package.json index 1e3bb21..268fa0e 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "node": ">=8.3.0" }, "dependencies": { + "@sendgrid/mail": "^7.3.0", "async": "^3.1.1", "body-parser": "^1.18.3", "canvas": "^2.4.1", @@ -24,7 +25,6 @@ "express": "^4.16.4", "express-session": "^1.16.1", "forwarded-for": "^1.0.1", - "nodemailer": "^6.1.0", "primus": "^7.3.2", "primus-emitter": "^3.1.1", "primus-rooms": "^3.4.1", -- 2.54.0