node package manager
It’s your turn. Help us improve JavaScript. Take the 2017 JavaScript Ecosystem Survey »



Simple wrapper around imap and mailparser that fetches, parses, and returns the most recent email that has been received by a gmail account.


Simply require in last-gmail, pass in the account details (only user and password are required, all other are optional and are documented here), and call getLastEmail. The function returns the results, and any errors, in the callback param.

var gmail = require('last-gmail');
var opts = {
    user: '',
    password: 'password'
gmail.getLastEmail(opts, function (err, email) {
    if (err) {
        return console.error(err);
    console.log('from:', email.from);
    email.text && console.log('text:', email.text);
    email.html && console.log('html:', email.html);