Skip to content

Commit c76efce

Browse files
committed
sendgrid emailer added
1 parent 86246d3 commit c76efce

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"dependencies": {
2121
"@mapbox/mapbox-sdk": "^0.12.1",
2222
"@supercharge/request-ip": "^1.1.2",
23-
"axios": "^0.21.1",
23+
"axios": "^0.21.4",
2424
"bcrypt": "^5.0.1",
2525
"cloudinary": "^1.25.1",
2626
"connect-mongo": "^3.2.0",

services/user.service.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const bcrypt = require('bcrypt');
44
const nodemailer = require('nodemailer');
55
const helper = require('../utils/helper');
66
const Transaction = require('../models/transaction.model');
7+
const axios = require("axios");
78

89
/* ------------ JWT Configs ----------- */
910

@@ -17,26 +18,20 @@ const jwt_headers = {
1718

1819
//sendmail... sends email to the user using nodemailer
1920
async function sendmail(to, subject, otp) {
20-
var transporter = nodemailer.createTransport({
21-
service: 'gmail',
22-
auth: {
23-
user: process.env.EMAIL,
24-
pass: process.env.PASS,
21+
const options = {
22+
method: 'POST',
23+
url: 'https://rapidprod-sendgrid-v1.p.rapidapi.com/mail/send',
24+
headers: {
25+
'content-type': 'application/json',
26+
'X-RapidAPI-Host': process.env.X_RAPIDAPI_HOST,
27+
'X-RapidAPI-Key': process.env.X_RAPIDAPI_KEY,
2528
},
26-
});
27-
// mail configurations
28-
var mailOptions = {
29-
from: process.env.EMAIL,
30-
to: to,
31-
subject: subject,
32-
html: `Your otp is :${otp}`,
33-
};
34-
await transporter.sendMail(mailOptions, function (error, info) {
35-
if (error) {
36-
console.log(error);
37-
} else {
38-
console.log('Email sent: ' + info.response);
39-
}
29+
data:`{"personalizations":[{"to":[{"email":"${to}"}],"subject":"${subject}"}],"from":{"email":"[email protected]"},"content":[{"type":"text/plain","value":"Your otp is : ${otp}"}]}`
30+
};
31+
axios.request(options).then(function (response) {
32+
console.log('Email sent: ' + response.data);
33+
}).catch(function (error) {
34+
console.error(error);
4035
});
4136
}
4237

0 commit comments

Comments
 (0)