browse by category or date

One of my project is using Node.JS running on Ubuntu Linux server. To send email, I am using email module. This module itself is just a wrapper for Sendmail. So you need to ensure that Sendmail is already installed and working properly in your server.

The usage of email module is quite simple. Here’s how to do it (taken from npm’s page):

//include the module 
var Email = require('path/to/email_module').Email;

//construct the new email message
var msg = new Email({ 
   from: "me@example.com", 
   to:   "you@example.com", 
   subject: "Knock knock...", 
   body: "Who's there?"
});

//send the email and handle any exception
msg.send(function (err){
   if (err){
      console.log('Error sending mail - %s', err.message);            
   } 
   else {
      //do something when email is successfully sent.
   }
});

When testing this module, I can send out email successfully. So I didn’t foresee any issue coming from it. But lately I started to receive reports that emails were not sent out. First, I checked Sendmail’s queue using mailq and sendmail -bp, but I found that the queue is empty.

When I checked Node.JS’s log, I notice this:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: write EPIPE
    at errnoException (net.js:904:11)
    at Object.afterWrite (net.js:720:19)
error: Forever detected script exited with code: 8
error: Forever restarting script for 3 time

It seems the email module was throwing unhandled exception. But I can’t make any sense where the error is actually originated. Hoping that someone already resolve this issue, I visited the module’s github issues page. Lucky me, I found that other people is having the exact same problem as mine.

github-node-email

With that, to solve this issue I just need to add the path to email’s configuration. But first, I need to find out the path of Sendmail:

user@ns3364112:~# which sendmail
/usr/sbin/sendmail

Then add the path to the configuration:

var msg = new Email({ 
   from: "me@example.com", 
   to:   "you@example.com", 
   subject: "Knock knock...", 
   body: "Who's there?",
   path: "/usr/sbin/sendmail"
});

Voila! The emails now sending out successfully.

GD Star Rating
loading...
Bug Fix: Node.JS Email Module Is Not Working, 3.5 out of 5 based on 2 ratings

Possibly relevant:

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Incoming Search

bugs, email, javascript, node.js

No Comment

Add Your Comment