isnode-mod-mailer
v0.0.8
Published
isnode Mailer (Email Sending) Module
Downloads
2
Readme
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:
- cfg - (Object) The configuration object
- host - (String) Hostname of the SMTP server
- port - (Integer) Port number of the SMTP server
- secure - (Boolean) True if requires a secure (TLS/SSL) connection, False if not
- auth - (Object) Optional. Authentication Object
- user - (String) Username to authenticate on mail server
- 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:
- emailObj - (Object) The email object
- from - (String) Email address to send from
- to - (String) Email address to send to
- subject - (String) Subject line of email
- text - (String) Textual content of email body
- html - (String) HTML content of email body
- cb - (Function) Callback Function. Returns the following attributes:
- err - (Object) Error Object
- res - (Object) Response Object
- success - (Boolean) True if email was sent, False if it was not
- message - (String) Free text message with more information. Usually of importance if success=false (email send failed).
- 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: "[email protected]",
to: "[email protected]",
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;
});