Skip to content

Instantly share code, notes, and snippets.

@Nikola-Andreev
Last active April 10, 2019 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nikola-Andreev/d4a385876572003b2b7138dea01f8669 to your computer and use it in GitHub Desktop.
Save Nikola-Andreev/d4a385876572003b2b7138dea01f8669 to your computer and use it in GitHub Desktop.
node-mailjet #78
const mailjet = require('node-mailjet');
require('dotenv').config();
async function main() {
const connection = mailjet.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE);
const sender = connection.post("send", {'version': 'v3.1'});
const viewer = {
firstName: "Nikola",
lastName: "Andreev",
email: "example1@mail.com"
};
const startup = {
email: "example2@mail.com",
name: "Nikola Andreev"
};
const input = {
message: "Hello from MailJet."
};
try {
const resSendEmail = await sendContactEmail(viewer, startup, input.message);
console.log('send email', JSON.stringify(resSendEmail.response));
} catch (e) {
console.log(e); // Error: Unsuccessful: 400 Missing mandatory property.
}
async function sendContactEmail(issuer, receiver, message) {
return sender.request({
FromEmail: 'xxx' + issuer.email,
Recipients: [{Email: receiver.email}],
Vars: {
receiverFirstName: receiver.name,
senderFirstName: issuer.firstName,
senderLastName: issuer.lastName,
senderEmail: issuer.email,
message: message
}
})
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment