Last active
April 10, 2019 14:25
-
-
Save Nikola-Andreev/d4a385876572003b2b7138dea01f8669 to your computer and use it in GitHub Desktop.
node-mailjet #78
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
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