Skip to content
Draft
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
20 changes: 8 additions & 12 deletions compute/mailjet.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@

// [START compute_send]
const mailer = require('nodemailer');
const smtp = require('nodemailer-smtp-transport');

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>',
},
})
);
const transport = mailer.createTransport({
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>',
},
});

const json = await transport.sendMail({
from: 'ANOTHER_EMAIL@ANOTHER_EXAMPLE.COM', // From address
Expand Down
3 changes: 1 addition & 2 deletions compute/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"dependencies": {
"@google-cloud/compute": "^4.0.0",
"@sendgrid/mail": "^8.0.0",
"nodemailer": "^6.0.0",
"nodemailer-smtp-transport": "^2.7.4",
"nodemailer": "^9.0.0",
Comment thread
angelcaamal marked this conversation as resolved.
"sinon": "^19.0.2"
},
"devDependencies": {
Expand Down
22 changes: 9 additions & 13 deletions compute/test/mailjet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ describe('mailjet', () => {
it('should send an email', () => {
proxyquire('../mailjet', {
nodemailer: {
createTransport: arg => {
assert.strictEqual(arg, 'test');
createTransport: options => {
assert.deepStrictEqual(options, {
host: 'in.mailjet.com',
port: 2525,
auth: {
user: 'foo',
pass: 'bar',
},
});
return {
sendMail: payload => {
assert.deepStrictEqual(payload, {
Expand All @@ -39,17 +46,6 @@ describe('mailjet', () => {
};
},
},
'nodemailer-smtp-transport': options => {
assert.deepStrictEqual(options, {
host: 'in.mailjet.com',
port: 2525,
auth: {
user: 'foo',
pass: 'bar',
},
});
return 'test';
},
});
});
});
Loading