Giter VIP home page Giter VIP logo

mailjet-apiv3-nodejs-es2015's Introduction

alt text

Mailjet EcmaScript2015 Wrapper

Please welcome the new Mailjet experimental EcmaScript API wrapper! If you want a Stable ES5 version, click Here

It is basically a translation, implementing the new EcmaScript specifications.

Mailjet is an Email Service Provider (ESP). Visit the website and get comfortable!

For more details, see the full API Documentation

Getting started

first, create a project folder

mkdir mailjet-project && cd $_

Installation

if you want to get a global installation, you can add -g

npm install mailjet-next

Show me the code

To authenticate, go get your API key, and API secret here, open your favorite text editor and import the mailjet module

import MailjetClient from 'mailjet-next';

let mailjet = new Mailjet('apiKey', 'apiSecret');

Get cosy with Mailjet

Save your 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

And use it in your projects

const apiKey = process.env.MJ_APIKEY_PUBLIC;
const apiSecret = process.env.MJ_APIKEY_PRIVATE;

Store a Mailjet resource

// GET resource
let user = Mailjet.get('user');

// POST resource
let sender = Mailjet.post('sender');

Request your resource with a callback function

user.request((error, response, body) => {
	if (error)
		console.log (`Oops, something went wrong ${response.statusCode}`);
	else
		console.log (body);
});

Make the same request with a Promise

the request method actually returns a EventEmitter triggering success and error

user.request()
	.then((response) => {

	}, (error) => {

	});

Pass data to your requests

sender
	.request({ Email: '[email protected]' })
	.then(handleData, handleError);

Pass parameters as well as a callback

let getContacts = Mailjet.get('contact');

getContacts.request({Limit: 3}, handleContacts);

Request a resource with an ID

getContacts
	.id(2)
	.request(handleSingleContact);

Request a ressource with an Action

var postContact = Mailjet.post('contact');

postContact.action('managemanycontacts')
	.request({ContactLists, Contacts})
	.then(handleData, handleError);

Send an Email

var sendEmail = Mailjet.post('send');

var emailData = {
    'FromEmail': '[email protected]',
    'FromName': 'My Name',
    'Subject': 'Test with the NodeJS Mailjet wrapper',
    'Text-part': 'Hello NodeJs !',
    'Recipients': [{'Email': '[email protected]'}],
}

sendEmail
	.request(emailData)
    .then(handleData, handleError);

Send two Emails

var emailData = {
    'FromEmail': '[email protected]',
    'FromName': 'Guillaume badi',
    'Subject': 'Coucou Mailjet2',
    'Text-part': 'Hello World2',
    'Recipients': [{'Email': '[email protected]'}],
}

var emailData2 = emailData;
emailData2['Text-part'] = 'This is another Email';

sendEmail
	.request(emailData)
    .then(handleData, handleError);

sendEmail
	.request(emailData2)
    .then(handleData, handleError);

Contribute

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:

  • Fork the project.
  • Create a new branch.
  • Implement your feature or bug fix.
  • Add documentation to it.
  • Commit, push, open a pull request and voila.

TODO:

  • Add compatibility with duplicatefrom filter

mailjet-apiv3-nodejs-es2015's People

Contributors

arnaudbreton avatar fabien-zimmer avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.