Skip to content

Commit

Permalink
Merge pull request #19 from Codehackerone/emailer-changes
Browse files Browse the repository at this point in the history
Email service changed to sendgrid from nodemailer
  • Loading branch information
Codehackerone authored Jun 6, 2022
2 parents e3d10a0 + 05a1778 commit 3da757d
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 45 deletions.
7 changes: 4 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ MONGO_URI=[your_mongo_uri]
JWT_SECRET=[your_jwt_secret]
EXPIRY=[your_jwt_expiry_time]
SECRET=[your_secret_for_mongostore]
EMAIL=[your_email_address]
PASS=[your_email_password]
CLOUDINARY_CLOUD_NAME=[your_cloudinary_cloud_name]
CLOUDINARY_KEY=[your_cloudinary_key]
CLOUDINARY_SECRET=[your_cloudinary_secret]
MAPBOX_TOKEN=[your_mapbox_project]
MAPBOX_TOKEN=[your_mapbox_project]
X_RAPIDAPI_HOST=[your_rapidapi_sendgrid_host]
X_RAPIDAPI_KEY=[your_rapiapi_sendgrid_key]
SENDGRID_EMAIL=[no-reply@your_domain.com]
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

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

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand Down
3 changes: 0 additions & 3 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ about: Describe this issue template's purpose here.
title: ''
labels: ''
assignees: ''

---


1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
Expand Down
28 changes: 14 additions & 14 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ appearance, race, religion, or sexual identity and orientation.
Examples of behavior that contributes to creating a positive environment
include:

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

Examples of unacceptable behavior by participants include:

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

## Our Responsibilities

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

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
https://www.contributor-covenant.org/faq
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ Create a `.env` file then edit it with your settings. You will need:
- JWT_SECRET=[your_jwt_secret]
- EXPIRY=[your_jwt_expiry_time]
- SECRET=[your_secret_for_mongostore]
- EMAIL=[your_email_address]
- PASS=[your_email_password]
- CLOUDINARY_CLOUD_NAME=[your_cloudinary_cloud_name]
- CLOUDINARY_KEY=[your_cloudinary_key]
- CLOUDINARY_SECRET=[your_cloudinary_secret]
- MAPBOX_TOKEN=[your_mapbox_project]
- X_RAPIDAPI_HOST=[your_rapidapi_sendgrid_host]
- X_RAPIDAPI_KEY=[your_rapiapi_sendgrid_key]
- SENDGRID_EMAIL=[no-reply@your_domain.com]

### Running the project

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@mapbox/mapbox-sdk": "^0.12.1",
"@supercharge/request-ip": "^1.1.2",
"axios": "^0.21.1",
"axios": "^0.21.4",
"bcrypt": "^5.0.1",
"cloudinary": "^1.25.1",
"connect-mongo": "^3.2.0",
Expand Down
36 changes: 17 additions & 19 deletions services/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------- */

Expand All @@ -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
Expand Down

0 comments on commit 3da757d

Please sign in to comment.