Skip to content

Commit 3da757d

Browse files
Merge pull request #19 from Codehackerone/emailer-changes
Email service changed to sendgrid from nodemailer
2 parents e3d10a0 + 05a1778 commit 3da757d

File tree

9 files changed

+41
-45
lines changed

9 files changed

+41
-45
lines changed

.env.example

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ MONGO_URI=[your_mongo_uri]
44
JWT_SECRET=[your_jwt_secret]
55
EXPIRY=[your_jwt_expiry_time]
66
SECRET=[your_secret_for_mongostore]
7-
EMAIL=[your_email_address]
8-
PASS=[your_email_password]
97
CLOUDINARY_CLOUD_NAME=[your_cloudinary_cloud_name]
108
CLOUDINARY_KEY=[your_cloudinary_key]
119
CLOUDINARY_SECRET=[your_cloudinary_secret]
12-
MAPBOX_TOKEN=[your_mapbox_project]
10+
MAPBOX_TOKEN=[your_mapbox_project]
11+
X_RAPIDAPI_HOST=[your_rapidapi_sendgrid_host]
12+
X_RAPIDAPI_KEY=[your_rapiapi_sendgrid_key]
13+
SENDGRID_EMAIL=[no-reply@your_domain.com]

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ about: Create a report to help us improve
44
title: ''
55
labels: ''
66
assignees: ''
7-
87
---
98

109
**Describe the bug**
1110
A clear and concise description of what the bug is.
1211

1312
**To Reproduce**
1413
Steps to reproduce the behavior:
14+
1515
1. Go to '...'
1616
2. Click on '....'
1717
3. Scroll down to '....'

.github/ISSUE_TEMPLATE/custom.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@ about: Describe this issue template's purpose here.
44
title: ''
55
labels: ''
66
assignees: ''
7-
87
---
9-
10-

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ about: Suggest an idea for this project
44
title: ''
55
labels: ''
66
assignees: ''
7-
87
---
98

109
**Is your feature request related to a problem? Please describe.**

CODE_OF_CONDUCT.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ appearance, race, religion, or sexual identity and orientation.
1414
Examples of behavior that contributes to creating a positive environment
1515
include:
1616

17-
* Using welcoming and inclusive language
18-
* Being respectful of differing viewpoints and experiences
19-
* Gracefully accepting constructive criticism
20-
* Focusing on what is best for the community
21-
* Showing empathy towards other community members
17+
- Using welcoming and inclusive language
18+
- Being respectful of differing viewpoints and experiences
19+
- Gracefully accepting constructive criticism
20+
- Focusing on what is best for the community
21+
- Showing empathy towards other community members
2222

2323
Examples of unacceptable behavior by participants include:
2424

25-
* The use of sexualized language or imagery and unwelcome sexual attention or
26-
advances
27-
* Trolling, insulting/derogatory comments, and personal or political attacks
28-
* Public or private harassment
29-
* Publishing others' private information, such as a physical or electronic
30-
address, without explicit permission
31-
* Other conduct which could reasonably be considered inappropriate in a
32-
professional setting
25+
- The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
- Trolling, insulting/derogatory comments, and personal or political attacks
28+
- Public or private harassment
29+
- Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
- Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
3333

3434
## Our Responsibilities
3535

@@ -73,4 +73,4 @@ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.ht
7373
[homepage]: https://www.contributor-covenant.org
7474

7575
For answers to common questions about this code of conduct, see
76-
https://www.contributor-covenant.org/faq
76+
https://www.contributor-covenant.org/faq

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,13 @@ Create a `.env` file then edit it with your settings. You will need:
9090
- JWT_SECRET=[your_jwt_secret]
9191
- EXPIRY=[your_jwt_expiry_time]
9292
- SECRET=[your_secret_for_mongostore]
93-
- EMAIL=[your_email_address]
94-
- PASS=[your_email_password]
9593
- CLOUDINARY_CLOUD_NAME=[your_cloudinary_cloud_name]
9694
- CLOUDINARY_KEY=[your_cloudinary_key]
9795
- CLOUDINARY_SECRET=[your_cloudinary_secret]
9896
- MAPBOX_TOKEN=[your_mapbox_project]
97+
- X_RAPIDAPI_HOST=[your_rapidapi_sendgrid_host]
98+
- X_RAPIDAPI_KEY=[your_rapiapi_sendgrid_key]
99+
- SENDGRID_EMAIL=[no-reply@your_domain.com]
99100

100101
### Running the project
101102

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: 17 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,27 +18,24 @@ 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}`,
29+
data: `{"personalizations":[{"to":[{"email":"${to}"}],"subject":"${subject}"}],"from":{"email":"[email protected]"},"content":[{"type":"text/plain","value":"Your otp is : ${otp}"}]}`,
3330
};
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-
}
40-
});
31+
axios
32+
.request(options)
33+
.then(function (response) {
34+
console.log('Email sent: ' + response.data);
35+
})
36+
.catch(function (error) {
37+
console.error(error);
38+
});
4139
}
4240

4341
// Register... receives user object and creates new user document in the DB

0 commit comments

Comments
 (0)