Skip to content
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

Upgrade Sendgrid version in Compute sample #211

Merged
merged 2 commits into from
Sep 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion computeengine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"googleapis": "^12.2.0",
"nodemailer": "^2.4.1",
"nodemailer-smtp-transport": "^2.5.0",
"sendgrid": "^2.0.0"
"sendgrid": "^4.0.1"
},
"devDependencies": {
"mocha": "^3.0.2"
Expand Down
32 changes: 23 additions & 9 deletions computeengine/sendgrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,33 @@
'use strict';

// [START send]
// This sample is based off of https://www.npmjs.com/package/sendgrid#without-mail-helper-class
var Sendgrid = require('sendgrid')(
process.env.SENDGRID_API_KEY || '<your-sendgrid-api-key>'
);

Sendgrid.send({
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) {
return console.log(err);
var request = Sendgrid.emptyRequest({
method: 'POST',
path: '/v3/mail/send',
body: {
personalizations: [{
to: [{ email: '[email protected]' }],
subject: 'Sendgrid test email from Node.js on Google Cloud Platform'
}],
from: { email: '[email protected]' },
content: [{
type: 'text/plain',
value: 'Hello!\n\nThis a Sendgrid test email from Node.js on Google Cloud Platform.'
}]
}
console.log(json);
});

Sendgrid.API(request, function (error, response) {
if (error) {
console.log('Mail not sent; see error message below.');
} else {
console.log('Mail sent successfully!');
}
console.log(response);
});
// [END send]
25 changes: 18 additions & 7 deletions computeengine/test/sendgrid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,25 @@ describe('computeengine:sendgrid', function () {
sendgrid: function (key) {
assert.equal(key, 'foo');
return {
send: function (payload, cb) {
assert.deepEqual(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.'
emptyRequest: function (x) {
return x;
},
API: function (request, cb) {
assert.deepEqual(request, {
method: 'POST',
path: '/v3/mail/send',
body: {
personalizations: [{
to: [{ email: '[email protected]' }],
subject: 'Sendgrid test email from Node.js on Google Cloud Platform'
}],
from: { email: '[email protected]' },
content: [{
type: 'text/plain',
value: 'Hello!\n\nThis a Sendgrid test email from Node.js on Google Cloud Platform.'
}]
}
});
cb('done');
done();
}
};
Expand Down