-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added requested Mailjet samples. #102
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## Express.js + Mailjet on Google App Engine | ||
|
||
> [Mailjet][1] is an all-in-one email service provider. | ||
> | ||
> – www.mailjet.com | ||
This sample application demonstrates how to use [Express.js][2] and | ||
[node-mailjet][3] to send transactional email on [Google App Engine][4]. | ||
|
||
You can also read the [Mailjet documentation][5]. | ||
|
||
[1]: https://www.mailjet.com/ | ||
[2]: http://expressjs.com | ||
[3]: https://github.com/mailjet/mailjet-apiv3-nodejs | ||
[4]: https://cloud.google.com/appengine | ||
[5]: https://dev.mailjet.com/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2016, Google, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
var express = require('express'); | ||
var path = require('path'); | ||
var bodyParser = require('body-parser'); | ||
|
||
// [START setup] | ||
var Mailjet = require('node-mailjet').connect( | ||
process.env.MJ_APIKEY_PUBLIC, | ||
process.env.MJ_APIKEY_PRIVATE | ||
); | ||
// [END setup] | ||
|
||
var app = express(); | ||
|
||
// Setup view engine | ||
app.set('views', path.join(__dirname, 'views')); | ||
app.set('view engine', 'jade'); | ||
|
||
// Parse form data | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
|
||
// [START index] | ||
app.get('/', function(req, res) { | ||
res.render('index'); | ||
}); | ||
// [END index] | ||
|
||
// [START hello] | ||
app.post('/hello', function(req, res, next) { | ||
var options = { | ||
// 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>' | ||
}; | ||
|
||
var request = Mailjet.post('send').request(options); | ||
|
||
request | ||
.on('success', function (response, body) { | ||
console.log(response.statusCode, body); | ||
// Render the index route on success | ||
return res.render('index', { | ||
sent: true | ||
}); | ||
}) | ||
.on('error', function (err) { | ||
return next(err); | ||
}); | ||
}); | ||
// [END hello] | ||
|
||
// [START server] | ||
var server = app.listen( | ||
process.env.PORT || 8080, | ||
'0.0.0.0', | ||
function () { | ||
var address = server.address().address; | ||
var port = server.address().port; | ||
console.log('App listening at http://%s:%s', address, port); | ||
console.log('Press Ctrl+C to quit.'); | ||
} | ||
); | ||
// [END server] | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2016, Google, Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START app_yaml] | ||
runtime: nodejs | ||
vm: true | ||
env_variables: | ||
MJ_APIKEY_PUBLIC: <your-mj-apikey-public> | ||
MJ_APIKEY_PRIVATE: <your-mj-apikey-private> | ||
|
||
skip_files: | ||
- ^(.*/)?.*/node_modules/.*$ | ||
# [END app_yaml] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "appengine-mailjet", | ||
"description": "An example of using Mailjet in Node.js on Google App Engine.", | ||
"version": "0.0.1", | ||
"private": true, | ||
"license": "Apache Version 2.0", | ||
"author": "Google Inc.", | ||
"engines": { | ||
"node": "~4.2" | ||
}, | ||
"scripts": { | ||
"start": "node app.js", | ||
"deploy": "gcloud preview app deploy" | ||
}, | ||
"dependencies": { | ||
"body-parser": "^1.14.2", | ||
"express": "^4.13.4", | ||
"jade": "^1.11.0", | ||
"node-mailjet": "^1.1.0" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2016, Google, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
doctype html | ||
html | ||
head | ||
title= title | ||
body | ||
h1 Hello World! | ||
p Express.js + Mailjet on Google App Engine. | ||
hr | ||
if sent | ||
p Email sent! | ||
else | ||
form(name="hello", action="/hello", method="post") | ||
input(type="email", placeholder="Enter your email to send yourself a Hello World message", name="email", style="width: 50%; margin-right: 15px;") | ||
input(type="submit", value="Send") |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2016, Google, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
// [START send] | ||
var mailer = require('nodemailer'); | ||
var smtp = require('nodemailer-smtp-transport'); | ||
|
||
var transport = mailer.createTransport(smtp({ | ||
service: 'Mailjet', | ||
auth: { | ||
user: process.env.MAILJET_API_KEY || '<your-mailjet-api-key', | ||
pass: process.env.MAILJET_API_SECRET || '<your-mailjet-api-secret>' | ||
} | ||
})); | ||
|
||
transport.sendMail({ | ||
from: 'ANOTHER_EMAIL@ANOTHER_EXAMPLE.COM', // From address | ||
to: '[email protected]', // To address | ||
subject: 'test email from Node.js on Google Cloud Platform', // Subject | ||
text: 'Hello!\n\nThis a test email from Node.js.' // Content | ||
}, function (err, json) { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log(json); | ||
} | ||
}); | ||
// [END send] |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2016, Google, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
var test = require('ava'); | ||
var proxyquire = require('proxyquire').noPreserveCache(); | ||
process.env.MAILJET_API_KEY = 'foo'; | ||
process.env.MAILJET_API_SECRET = 'bar'; | ||
|
||
test.cb('should send an email', function (t) { | ||
proxyquire('../../computeengine/mailjet.js', { | ||
nodemailer: { | ||
createTransport: function (arg) { | ||
t.is(arg, 'test'); | ||
return { | ||
sendMail: function (payload, cb) { | ||
t.same(payload, { | ||
from: 'ANOTHER_EMAIL@ANOTHER_EXAMPLE.COM', | ||
to: '[email protected]', | ||
subject: 'test email from Node.js on Google Cloud Platform', | ||
text: 'Hello!\n\nThis a test email from Node.js.' | ||
}); | ||
cb('done'); | ||
t.end(); | ||
} | ||
}; | ||
} | ||
}, | ||
'nodemailer-smtp-transport': function (options) { | ||
t.same(options, { | ||
service: 'Mailjet', | ||
auth: { | ||
user: 'foo', | ||
pass: 'bar' | ||
} | ||
}); | ||
return 'test'; | ||
} | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be configurable? Or does mailjet let you send from anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as they've verified that email address it will send.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmmmmkay. SGTM.
On Tue, Apr 19, 2016 at 1:10 PM Jason Dobry [email protected]
wrote: