-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from Codehackerone/emailer-changes
Email service changed to sendgrid from nodemailer
- Loading branch information
Showing
9 changed files
with
41 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,4 @@ about: Describe this issue template's purpose here. | |
title: '' | ||
labels: '' | ||
assignees: '' | ||
|
||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ const bcrypt = require('bcrypt'); | |
const nodemailer = require('nodemailer'); | ||
const helper = require('../utils/helper'); | ||
const Transaction = require('../models/transaction.model'); | ||
const axios = require('axios'); | ||
|
||
/* ------------ JWT Configs ----------- */ | ||
|
||
|
@@ -17,27 +18,24 @@ const jwt_headers = { | |
|
||
//sendmail... sends email to the user using nodemailer | ||
async function sendmail(to, subject, otp) { | ||
var transporter = nodemailer.createTransport({ | ||
service: 'gmail', | ||
auth: { | ||
user: process.env.EMAIL, | ||
pass: process.env.PASS, | ||
const options = { | ||
method: 'POST', | ||
url: 'https://rapidprod-sendgrid-v1.p.rapidapi.com/mail/send', | ||
headers: { | ||
'content-type': 'application/json', | ||
'X-RapidAPI-Host': process.env.X_RAPIDAPI_HOST, | ||
'X-RapidAPI-Key': process.env.X_RAPIDAPI_KEY, | ||
}, | ||
}); | ||
// mail configurations | ||
var mailOptions = { | ||
from: process.env.EMAIL, | ||
to: to, | ||
subject: subject, | ||
html: `Your otp is :${otp}`, | ||
data: `{"personalizations":[{"to":[{"email":"${to}"}],"subject":"${subject}"}],"from":{"email":"[email protected]"},"content":[{"type":"text/plain","value":"Your otp is : ${otp}"}]}`, | ||
}; | ||
await transporter.sendMail(mailOptions, function (error, info) { | ||
if (error) { | ||
console.log(error); | ||
} else { | ||
console.log('Email sent: ' + info.response); | ||
} | ||
}); | ||
axios | ||
.request(options) | ||
.then(function (response) { | ||
console.log('Email sent: ' + response.data); | ||
}) | ||
.catch(function (error) { | ||
console.error(error); | ||
}); | ||
} | ||
|
||
// Register... receives user object and creates new user document in the DB | ||
|