-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(samples): update samples to use async/await and mocha (#183)
- Loading branch information
1 parent
bff0c5f
commit 41c76ec
Showing
16 changed files
with
287 additions
and
340 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,30 +19,26 @@ | |
const mailer = require('nodemailer'); | ||
const smtp = require('nodemailer-smtp-transport'); | ||
|
||
const transport = mailer.createTransport( | ||
smtp({ | ||
host: 'in.mailjet.com', | ||
port: 2525, | ||
auth: { | ||
user: process.env.MAILJET_API_KEY || '<your-mailjet-api-key', | ||
pass: process.env.MAILJET_API_SECRET || '<your-mailjet-api-secret>', | ||
}, | ||
}) | ||
); | ||
async function mailjet() { | ||
const transport = mailer.createTransport( | ||
smtp({ | ||
host: 'in.mailjet.com', | ||
port: 2525, | ||
auth: { | ||
user: process.env.MAILJET_API_KEY || '<your-mailjet-api-key', | ||
pass: process.env.MAILJET_API_SECRET || '<your-mailjet-api-secret>', | ||
}, | ||
}) | ||
); | ||
|
||
transport.sendMail( | ||
{ | ||
const json = await 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); | ||
} | ||
} | ||
); | ||
}); | ||
console.log(json); | ||
} | ||
mailjet().catch(console.error); | ||
|
||
// [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 |
---|---|---|
|
@@ -19,33 +19,31 @@ const Sendgrid = require('sendgrid')( | |
process.env.SENDGRID_API_KEY || '<your-sendgrid-api-key>' | ||
); | ||
|
||
const 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.', | ||
}, | ||
], | ||
}, | ||
}); | ||
async function sendgrid() { | ||
const 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.', | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
Sendgrid.API(request, function(error, response) { | ||
if (error) { | ||
console.log('Mail not sent; see error message below.'); | ||
} else { | ||
console.log('Mail sent successfully!'); | ||
} | ||
const response = await Sendgrid.API(request); | ||
console.log(response); | ||
}); | ||
} | ||
sendgrid().catch(console.error); | ||
|
||
// [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
Oops, something went wrong.