Sending Email Using Javascript

For my latest project, I was having some mail forwared development using Javascript. Luckily for Node JS we already got some fancy easy to use library.

We’re using Marak Node Mailer for the project, you can check it on Github

https://github.com/Marak/node_mailer

and you can use npm to install it, don’t forget to install the latest version

npm install nodemailer@latest

Code Jumble

Here’s some usage example, I’m using SMTP for this example. You can check more example at their site Nodemailer documentations

// JavaScript Document
var nodemailer = require("nodemailer");

var transport = nodemailer.createTransport("SMTP", {
    host: "smtp.yourhost.com", // hostname
    secureConnection: false, // use SSL
    port: 123, // port for secure SMTP
    auth: {
        user: "username",
        pass: "password"
    }
});

transport.sendMail({
    from: "test@somemail.com",
    to: "testto@somemail.com",
    subject: "Test SMPT Mail using NodeJS Mailer",
    text: "Tralalalallala"
}, function(error, responseStatus){
    if(!error){
        console.log(responseStatus.message); // response from the server
    }
});

Published: July 28 2012

blog comments powered by Disqus