Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
node-mailjet
Advanced tools
Please welcome the new Mailjet official NodeJS API wrapper!
Mailjet is an Email Service Provider (ESP). Visit the website and get comfortable!
Every code examples can be find on the Mailjet Documentation
(Please refer to the Mailjet Documentation Repository to contribute to the documentation examples)
first, create a project folder
mkdir mailjet-project && cd $_
if you want to get a global installation, you can add -g
npm install node-mailjet
To authenticate, go get your API key, and API secret here, open your favorite text editor and import the mailjet module
var Mailjet = require('node-mailjet').connect('api key', 'api secret');
API_KEY
and API_SECRET
:echo 'export MJ_APIKEY_PUBLIC=MY_API_KEY' >> ~/.zshrc
echo 'export MJ_APIKEY_PRIVATE=MY_API_SECRET' >> ~/.zshrc
source ~/.zshrc
replace zshrc
with bash_profile
if you are simply using bash
var apiKey = process.env.MJ_APIKEY_PUBLIC,
apiSecret = process.env.MJ_APIKEY_PRIVATE;
// GET resource
var user = Mailjet.get('user');
// POST resource
var sender = Mailjet.post('sender');
user.request(function (error, response, body) {
if (error)
console.log ('Oops, something went wrong ' + response.statusCode);
else
console.log (body);
});
the request method actually returns a EventEmitter triggering success
and error
user.request()
.on('error', function (error, response) {})
.on('success', function (response, body) {});
sender.request({ Email: 'mr@mailjet.com' })
.on('success', handleData)
.on('error', handleError);
var getContacts = Mailjet.get('contact');
getContacts.request({Limit: 3}, handleContacts);
getContacts.id(2).request(handleSingleContact);
var postContact = Mailjet.post('contact');
postContact.action('managemanycontacts').request({
ContactLists: MyContactListsArray,
Contacts: MyContactsArray,
}, handlePostResponse);
var sendEmail = Mailjet.post('send');
var emailData = {
'FromEmail': 'my@email.com',
'FromName': 'My Name',
'Subject': 'Test with the NodeJS Mailjet wrapper',
'Text-part': 'Hello NodeJs !',
'Recipients': [{'Email': 'roger@smith.com'}],
'Attachments': [{
"Content-Type": "text-plain",
"Filename": "test.txt",
"Content": "VGhpcyBpcyB5b3VyIGF0dGFjaGVkIGZpbGUhISEK",
}],
}
sendEmail
.request(emailData)
.on('success', handlePostResponse)
.on('error', handleError);
var emailData = {
'FromEmail': 'gbadi@student.42.fr',
'FromName': 'Guillaume badi',
'Subject': 'Coucou Mailjet2',
'Text-part': 'Hello World2',
'Recipients': [{'Email': 'gbadi@mailjet.com'}],
}
var emailData2 = emailData;
emailData2['Text-part'] = 'This is another Email';
sendEmail
.request(emailData)
.on('success', handleData)
.on('error', handleError);
sendEmail
.request(emailData2)
.on('success', handleData)
.on('error', handleError);
var mailjet = require ('./mailjet-client')
.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
function handleError (err) {
throw new Error(err.ErrorMessage);
}
function newContact (email) {
mailjet.post('contact')
.request({Email: email})
.on('error', handleError);
}
function testEmail (text) {
email = {};
email['FromName'] = 'Your Name';
email['FromEmail'] = 'Your Sender Adress';
email['Subject'] = 'Test Email';
email['Recipients'] = [{Email: 'Your email'}];
email['Text-Part'] = text;
mailjet.post('send')
.request(email)
.on('error', handleError);
}
testEmail('Hello World!');
npm test
Mailjet loves developers. You can be part of this project!
This wrapper is a great introduction to the open source world, check out the code!
Feel free to ask anything, and contribute:
TODO:
FAQs
Mailjet API client
The npm package node-mailjet receives a total of 57,921 weekly downloads. As such, node-mailjet popularity was classified as popular.
We found that node-mailjet demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.