Skip to content

Commit

Permalink
Fixes 410: generic smtp mail service added (fossasia#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
poonai authored and niranjan94 committed Oct 20, 2017
1 parent 23e0c06 commit 76b636d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
12 changes: 12 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@
},
"HOSTNAME": {
"description": "Hostname of your web application."
},
"SMTP_USERNAME": {
"description": "SMTP username"
},
"SMTP_PASSWORD": {
"description": "SMTP password"
},
"SMTP_HOST": {
"description": "SMTP host address"
},
"SMTP_PORT": {
"description": "SMTP port"
}
},
"buildpacks": [
Expand Down
19 changes: 8 additions & 11 deletions backend/mailer.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
var exports = module.exports = {};

var nodemailer = require('nodemailer');
var sgTransport = require('nodemailer-sendgrid-transport');
var jade = require('jade');
var hostname =process.env.HOSTNAME || 'yaydoc.herokuapp.com';
var validation = require('../public/scripts/validation.js');

const options = {
service: 'SendGrid',
var client = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: parseInt(process.env.SMTP_PORT),
auth: {
api_user: process.env.SENDGRID_USERNAME,
api_key: process.env.SENDGRID_PASSWORD
user: process.env.SMTP_USERNAME,
pass: process.env.SMTP_PASSWORD
}
};
});

exports.sendEmail = function (data) {
var client = nodemailer.createTransport(sgTransport(options));

var previewURL = data.previewURL;
var downloadURL = 'http://' + hostname + '/download/' + data.email + '/' + data.uniqueId;
var githubDeployURL = "";
Expand All @@ -42,7 +40,7 @@ exports.sendEmail = function (data) {
});

client.sendMail({
from: 'info@yaydoc.com',
from: 'info@yaydoc.org',
to: data.email,
subject: 'Preview your generated docs - Yaydoc',
text: textContent,
Expand All @@ -57,14 +55,13 @@ exports.sendEmail = function (data) {
};

exports.sendMailOnBuild = function (buildStatus, email, repository) {
var client = nodemailer.createTransport(sgTransport(options));
var status = buildStatus ? "Passed" : "Failed";

var textContent = status + ': ' + repository.name + ' - Yaydoc';
var htmlContent = status + ': ' + repository.name + ' - Yaydoc';

client.sendMail({
from: 'info@yaydoc.com',
from: 'info@yaydoc.org',
to: email,
subject: status + ': ' + repository.name + ' - Yaydoc',
text: textContent,
Expand Down
12 changes: 7 additions & 5 deletions docs/installation/heroku.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Installing Yaydoc on Heroku
Heroku is a cloud platform as a service (PaaS) that is used as a web application deployment model. The Yaydoc Web User Interface is a NodeJS application and Heroku makes it really easy to deploy and scale Node.js applications in the cloud.

## One-click Heroku deployment
## One-click Heroku deployment
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)

## Manual Deployment
Expand All @@ -11,14 +11,14 @@ Even though we offer the One-click Heroku deployment, performing a manual deploy
* If you have a linux based Operating Systems, type the following command in the terminal

wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh

*Note:-* Details for other Operating Systems can be found at https://devcenter.heroku.com/articles/heroku-cli

### Login to Heroku Server (Create an account if it doesn’t exist)
* Type in the following command in your server, enter credentials and login

heroku login

### Deploy Yaydoc to Heroku
* Clone the original yaydoc repository or your own fork and move to the directory of the cloned repository

Expand Down Expand Up @@ -48,8 +48,10 @@ Even though we offer the One-click Heroku deployment, performing a manual deploy
heroku config:set MONGODB_URI=mongodb://<username>:<password>@ds151662.mlab.com:51662/<mlab-db-name>
heroku config:set PYPANDOC_PANDOC=~/vendor/pandoc/bin/pandoc
heroku config:set SECRET=<a-very-secret-token>
heroku config:set SENDGRID_PASSWORD=<sengrid-password>
heroku config:set SENDGRID_USERNAME=<sendgrid-username>
heroku config:set SMTP_USERNAME=<smtp-username>
heroku config:set SMTP_PASSWORD=<smtp-password>
heroku config:set SMTP_HOST=<smtp-host>
heroku config:set SMTP_PORT=<smtp-port>
* Now deploy your code

git push heroku master
Expand Down
6 changes: 4 additions & 2 deletions kubernetes/yamls/yaydoc/configmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ data:
HOSTNAME: "yaydoc.org"
MONGODB_URI: "mongodb://mongo.mongo:27017/yaydoc"
SECRET: "anabsolutescrettokenforyaydoc"
SENDGRID_USERNAME: "XXXXXXXXXXXX"
SENDGRID_PASSWORD: "XXXXXXXXXXXX"
SMTP_USERNAME: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
SMTP_PASSWORD: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
SMTP_HOST: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
SMTP_PORT: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
kind: ConfigMap
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"mongoose": "^4.11.0",
"morgan": "~1.8.1",
"nodemailer": "^4.0.1",
"nodemailer-sendgrid-transport": "^0.2.0",
"passport": "^0.3.2",
"passport-github": "^1.1.0",
"passport-heroku": "^1.0.0",
Expand Down

0 comments on commit 76b636d

Please sign in to comment.