Mailer
The Mailer module allows you to send an email message in response to events occurring in Moogsoft Onprem. For example, you can use it in the Notifier.js Moobot to send email to users when they are invited to a Situation Room.
Load the module
The Mailer module is available to load into any standard Moobot. To load it, define a new global variable at the top of the Moobot Javascript file. For example:
var mailer = MooBot.loadModule('Mailer');
Method reference
The Mailer module uses the following methods.
intTransport
Defines the mail server information needed to send the email in the send function.
Request arguments
The method takes the following arguments.
Name | Type | Required | Description |
---|---|---|---|
| Object | Yes | A JSON object specifying connection properties. |
Use the following port guidelines:
If using port 587, set
start_tls
to true anduse_tls
to false.If using port 465, set
start_tls
to true anduse_tls
to true.If using port 25, set
start_tls
to false anduse_tls
to false (or comment out both properties).
If you omit the password
field, an unauthenticated connection is created between Mailer and the server.
Response
None.
Example
Example use of the intTransport
method to specify a mailserver, port and other connection details:
mailer.initTransport( { server : "smtp.mailserver.com", port : 2525, account : "user@mailserver.com", password : "m00gsoft", isEncrypted : false, start_tls : false, use_tls : false });
send
Sends the email message. You must define a callback function in the same Moobot that is referenced in the mailMsg executed after a successful transmission.
Request arguments
The method takes the following arguments.
Name | Type | Required | Description |
---|---|---|---|
| Object | Yes | A JSON object containing the fields required to populate the email message. |
Response
None.
Example
Examples of the send
method to send an email message, which can include multiple recipients:
var mailMsg = { to : "destination@mail.com", subject : "Situation Room Notification", message : "email body", invite : invite, // do not change bot : MooBot.self, // do not change callback: "sendSuccess", // the name of the function to run in this Moobot args : [ invite_id, "Sent successfully", vector ] // do not change }; mailer.send(mailMsg);
var mailMsg = { to : ["destination@mail.com","destination1@gmail.com"], subject : "Situation Room Notification", message : "email body", invite : invite, // do not change bot : MooBot.self, // do not change callback: "sendSuccess", // the name of the function to run in this Moobot args : [ invite_id, "Sent successfully", vector ] // do not change }; mailer.send(mailMsg);
var emails = []; emails.push("destination@gmail.com"); emails.push("destination1@gmail.com"); var mailMsg = { to : emails, subject : "Situation Room Notification", message : "email body", invite : invite, // do not change bot : MooBot.self, // do not change callback: "sendSuccess", // the name of the function to run in this Moobot args : [ invite_id, "Sent successfully", vector ] // do not change }; mailer.send(mailMsg);