Created
September 11, 2016 01:23
-
-
Save sumn2u/0e8a36874583612eebba9dfa9c60b9a3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var express = require('express') | |
var bodyParser = require('body-parser') | |
var request = require('request') | |
var app = express() | |
var Mailjet = require('node-mailjet').connect( | |
process.env.MJ_APIKEY_PUBLIC, | |
process.env.MJ_APIKEY_PRIVATE | |
); | |
app.set('port', (process.env.PORT || 3030)) | |
// Process application/x-www-form-urlencoded | |
app.use(bodyParser.urlencoded({extended: false})) | |
// Process application/json | |
app.use(bodyParser.json()) | |
// Index route | |
app.get('/', function (req, res) { | |
res.send('Hello world, I am a chat bot') | |
}) | |
app.post('/hello', function (req, res, next) { | |
console.log("request ==>", req.body); | |
var emailData = { | |
// From | |
FromEmail: '[email protected]', | |
FromName: 'Mailjet Demo', | |
// To | |
Recipients: [{ Email: req.body.email }], | |
// Subject | |
Subject: 'Hello World!', | |
// Body | |
'Text-part': 'Mailjet on Google App Engine with Node.js', | |
'Html-part': '<h3>Mailjet on Google App Engine with Node.js</h3>' | |
}; | |
app.post('/hello', function (req, res, next) { | |
console.log("request ==>", req.body); | |
var emailData = { | |
'FromEmail': '[email protected]', | |
'FromName': 'My Name', | |
'Subject': 'Test with the NodeJS Mailjet wrapper', | |
'Text-part': 'Hello NodeJs !', | |
'Recipients': [{'Email': '[email protected]'}], | |
'Attachments': [{ | |
"Content-Type": "text-plain", | |
"Filename": "test.txt", | |
"Content": "VGhpcyBpcyB5b3VyIGF0dGFjaGVkIGZpbGUhISEK", | |
}], | |
} | |
Mailjet.post('send') | |
.request(emailData) | |
.then(function(succ){ | |
console.log("success", succ); | |
}) | |
.catch(function(errr){ | |
console.log("errr", errr); | |
}); | |
}); | |
// Spin up the server | |
app.listen(app.get('port'), function() { | |
console.log('running on port', app.get('port')) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment