User Tools

Site Tools


sib:callers:smtpcaller

SMTPCaller

Overview

The SIB SMTP Caller is a specific caller used to send emails from messages on SIB MQTT topics.

Details

Modulesib_smtpcaller
Version1.3.0

Workflow

  • Subscribe: .custom.topic
    • on message:
      • custom.inputFormat
        • Substitute missing message parts from the .custom.default configuration
        • Send email
        • Add status information to message
        • Publish resulting message on responseTopic

Custom configuration

smtpcaller/custom.js
var SMTPCallerCustom = {
	_id: "SMTPSample:1",
	_name: "SMTPCallerSample",
	default: {
		to: "user@host.se",
		from: "sender@otherhost.se",
		subject: "Some default subject here",
		text: "Some random text for non HTML enabled clients",
		html: "<b>HTML</b> formatted default mail body"
	},
	inputFormat: (topic, msg, cb, mysqlConnection)=>{
		cb(msg);
	},
	loggerCfg: {
		dest: {
			file: false,
			console: true,
			mqtt: true
		}
	},
	outputFormat: (topic, msg, cb, mysqlConnection)=>{
		cb(msg);
	},
	smtp: {
		host: "my.mailhost.com",
		port: 465,
		secure: true,
		auth: {
			user: "authenticated_user",
			pass: "thePassword!"
		},
		tls: {
			rejectUnauthorized: false
		}
	},
	mqtt: "mqtt://localhost",
	topic: "SIB/test/SMTPCaller"
};
 
module.exports = SMTPCallerCustom;
  • _id: The unique ID of this service
  • _name: A plaintext description of this service
  • default: The default message if parameters are left out on the MQTT topic
    • to: The default recipient of the message
    • from: The default sender of the message
    • subject: The default subject of the message
    • text: The default plaintext content of the email message
    • html: The default HTML formatted mail body
  • inputFormat(topic, msg, callback, mysqlConnection): The method that is run on service activation. The original message is passed as the argument and the input value to the callback must be a JSON formatted message conforming to the SIB message standard. If the message is null when returning from inputFormat no action is taken by the caller.
  • loggerCfg: A JSON Object defining what logger actions should be active for this service (see Logger Configuration
  • outputFormat(topic, msg, callback, mysqlConnection): This message is run on the response data before publishing to the response topic. The response message is passed as the argument and the input to the callback must be a JSON formatted message conforming to the SIB message standard.
  • smtp: The SMTP configuration, for more information see the nodemailer NPM package
    • host: The SMTP server
    • port: The port on the SMTP server on which to send messages
    • secure: Wether to use TLS or not
    • auth:
      • user: The user to log in as on the SMTP server
      • pass: The password to use for login
    • … all parameters that can be passed to the NodeMailer.createTransport function
  • mqtt: The MQTT connection string for the internal MQTT transport
  • topic: The MQTT topic to subscribe to on the internal MQTT transport
sib/callers/smtpcaller.txt · Last modified: 2019/05/13 11:40 by hubbe