Skip to content

Commit

Permalink
⏪ reverted to basic email service for dev env
Browse files Browse the repository at this point in the history
  • Loading branch information
fave77 committed Jun 11, 2021
1 parent c82c629 commit 2c8ed29
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
![example workflow name](https://github.com/fave77/pbchess/workflows/heroku/badge.svg)
[![Netlify Status](https://api.netlify.com/api/v1/badges/9dfb4c24-589e-4679-a331-a85a8e1a5382/deploy-status)](https://app.netlify.com/sites/pbchess/deploys)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/e3ba9e6a3bb84fc7a3c6905c8e1af48c)](https://app.codacy.com/gh/fave77/pbchess?utm_source=github.com&utm_medium=referral&utm_content=fave77/pbchess&utm_campaign=Badge_Grade)
[![codecov](https://codecov.io/gh/fave77/pbchess/branch/develop/graph/badge.svg?token=VZJBLBMUH6)](https://codecov.io/gh/fave77/pbchess)
[![Known Vulnerabilities](https://snyk.io/test/github/fave77/pbchess/badge.svg)](https://snyk.io/test/github/fave77/pbchess)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
![](https://img.shields.io/github/stars/fave77/pbchess.svg)
Expand Down
53 changes: 39 additions & 14 deletions server/src/services/email.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,46 @@ const googleClientSecret = process.env.GOOGLE_CLIENT_SECRET;
const googleRefreshToken = process.env.GOOGLE_REFRESH_TOKEN;
const redirectURL = 'https://developers.google.com/oauthplayground';
const user = process.env.EMAIL;

const pass = process.env.PASS;
const sendMail = async (email, subject, message) => {

try {

/* The following oAuth2 implemenatation is not intended for development
* since refresh token expires after 7 days for testing application on GCP
* as mentioned here - https://github.com/fave77/pbchess/issues/134
*/


// Creating an oAuth2 Client
const oAuth2Client = new google.auth.OAuth2(googleClientID, googleClientSecret, redirectURL);
oAuth2Client.setCredentials({refresh_token: googleRefreshToken});
// const oAuth2Client = new google.auth.OAuth2(googleClientID, googleClientSecret, redirectURL);
// oAuth2Client.setCredentials({refresh_token: googleRefreshToken});

// // Gets the access token at that moment
// const accessToken = await oAuth2Client.getAccessToken();

// Gets the access token at that moment
const accessToken = await oAuth2Client.getAccessToken();
// Transporter object specifying the type of email used
// const transporter = nodemailer.createTransport({
// host: 'smtp.gmail.com',
// port: 465,
// secure: true,
// auth:{
// type: 'OAuth2',
// user: user,
// clientId: googleClientID,
// clientSecret: googleClientSecret,
// refreshToken: googleRefreshToken,
// accessToken: accessToken
// }
// });

// Transporter object specifying the type of email used
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
service: 'gmail',
auth:{
type: 'OAuth2',
user: user,
clientId: googleClientID,
clientSecret: googleClientSecret,
refreshToken: googleRefreshToken,
accessToken: accessToken
}
pass: pass
}
});

// The Sender and recepient emails
Expand All @@ -38,6 +54,15 @@ const sendMail = async (email, subject, message) => {
subject: subject,
html: message
};

transporter.verify(function(error, success) {
if (error) {
console.log(error);
} else {
console.log("Server is ready to take our messages");
}
});


// Sends the mail
transporter.sendMail(options, (error, data) => {
Expand Down

0 comments on commit 2c8ed29

Please sign in to comment.