0.0.8 • Published 5 years ago

isnode-mod-mailer v0.0.8

Weekly downloads
8
License
-
Repository
github
Last release
5 years ago

ISNode Mailer Module

Introduction

This is just a module for the ISNode Framework. To learn how to use the framework, we strongly suggest obtaining a copy of the Hello World example.

The mailer module allows you to send email from your services. It currently supports sending email via SMTP connections.

Methods

connection(cfg)

Synchronous Constructor. Sets up an email server connection. Should be instantiated as a new object rather than just called directly.

Input Parameters:

  1. cfg - (Object) The configuration object
    1. host - (String) Hostname of the SMTP server
    2. port - (Integer) Port number of the SMTP server
    3. secure - (Boolean) True if requires a secure (TLS/SSL) connection, False if not
    4. auth - (Object) Optional. Authentication Object
      1. user - (String) Username to authenticate on mail server
      2. pass - (String) Password to authenticate on mail server

Returns: This method returns a "connection" object (connectionObject), which should be kept and the methods within it used to send emails.

Example

// The below use case assumes that you have an instance of the isnode master object

var mailCfg = {
  host: service.cfg().mailer.host,
  port: service.cfg().mailer.port,
  secure: service.cfg().mailer.secure,
  auth: {
    user: service.cfg().mailer.user,
    pass: service.cfg().mailer.password
  }
}

var mailer = new isnode.module("mailer").connection(mailCfg);

connectionObject.send(emailObj, cb)

Asynchronous Constructor. Sends an Email.

Input Parameters:

  1. emailObj - (Object) The email object
    1. from - (String) Email address to send from
    2. to - (String) Email address to send to
    3. subject - (String) Subject line of email
    4. text - (String) Textual content of email body
    5. html - (String) HTML content of email body
  2. cb - (Function) Callback Function. Returns the following attributes:
    1. err - (Object) Error Object
    2. res - (Object) Response Object
      1. success - (Boolean) True if email was sent, False if it was not
      2. message - (String) Free text message with more information. Usually of importance if success=false (email send failed).
      3. error - (Object) Freeform error object that may contain debug-level information as to why the email send failed.

Returns: Nothing directly. Refer to callback function.

Example

/* 
	The below use case assumes that you have an instance of the isnode master object.
	It also follows on from the description of the previous "connection" constructor and assumes that you have already followed the example and have a "mailer" object that is ready to use.
*/

var email = {
  from: "sender@test.com",
  to: "recipient@test.com",
  subject: "Test Email",
  text: "Text Version of Test Content for Email",
  html: "<p>HTML Version of Test Content for Email</p>"
}

mailer.send(email, function(err, res){
  if(err){
    console.log("Email Send Failed");
  } else {
    console.log("Email Send Succeeded");    
  }
  return;
});

0.0.8

5 years ago

0.0.5

5 years ago