Send mail with Mandrillapp and Node.js

by Dani Arlandis — on  ,  , 

cover-image

requisites

  • Node 0.6+
  • NPM
  • RequireJS
  • Have a count in Mandrillapp

Instalation

First we have to install Mandrill's API with npm package manager

npm install mandrill-api

How to use

To use the library you can simply declare an instance of Mandrillapp.

var mandrill = require('mandrill-api/mandrill');
var mandrill_client = new mandrill.Mandrill('YOUR_API_KEY');

We're almost ready to make requests and only need to configure SPF and DKIM and Check our domain.

Official documentation

Once you configured the domain we can use the API Mandrill:

var mandrill = require('mandrill-api/mandrill');

mandrill_client = new mandrill.Mandrill('YOUR_API_KEY');

var message = {
    "html": "contenido html",
    "text": "Ejemplo en texto",
    "subject": "Asunto",
    "from_email": "ejemplo@ejemplo.es",
    "from_name": "Nombre de ejemplo",
    "to": [{
        "email": "mailto@ejemplo.es",
        "name": "User",
        "type": "to"
    }],
    "headers": {
        "Reply-To": "ejemplo@ejemplo.es"
    }
};

var async = false;

var ip_pool = "Main Pool";

mandrill_client.messages.send({
        "message": message, "async": async, "ip_pool": ip_pool
    },
    function(result) {//Do something},
    function(e) {//Error handler}
);