Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

41 lines (32 sloc) 1.1 kb

sendgrid-stub

A node.js stub for the SendGrid library - this lets you send and receive emails locally during testing

Usage

Install

npm install sendgrid-stub

Use

var MailClient = require('sendgrid-stub').MailClient;
var SendGrid = require('sendgrid-stub').SendGrid;
var localAppserverMailClient = new MailClient("./sendgridEmails/");
var sendgrid = new SendGrid("username", "password");

//Send the email
sendgrid.send({
    to: "receiver@example.com",
    from: "hello@example.com",
    subject: "Test mail",
    html: "<b>Content</b>"
    text: "Content"
}, callback);

//Receive it again
localAppserverMailClient.getLatest(function(err, email){
    console.log(email);
}

//Purge inbox
localDashboardMailClient.deleteAll(function(){
    console.log("Deleted")
})

Background

I use this mock for testing webapps which make use of the SendGrid service. Just replace the sendgrid library with this stub, and pick up your e-mails with the mail client from: process.cwd()+"/sendgridEmails/"

All emails are written to disk as json objects.

Jump to Line
Something went wrong with that request. Please try again.