]> git.example.dev Git - binbsis50.git/commitdiff
replaced nodemailer with @sendgrid/mail
authorLuigi Pinca <luigipinca@gmail.com>
Sat, 17 Oct 2020 06:45:41 +0000 (08:45 +0200)
committerLuigi Pinca <luigipinca@gmail.com>
Sat, 17 Oct 2020 06:45:41 +0000 (08:45 +0200)
lib/email/mailer.js
package.json

index 4885c6288b1cb7a3a645f4320e5f44a4aacc2aaa..8e5d96def3a452ba8a644500a523bc4a728e678d 100644 (file)
@@ -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>/, 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 <no-reply@binb.co>',
       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
   );
 };
index 1e3bb214ab65e14d3d297ca1d4e5fcdac96e5193..268fa0e26bfec542c9894562413b4abf66e25125 100644 (file)
@@ -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",