Mailer

class
 new Mailer()  extends Service

A basic Mailer based on the nodemailer module

Inside config it is the nodemailer module option for the method createTransport ( https://nodemailer.com/ )

Only ses transport module is installed by default

Parameters
config: { ... }

class Mailer extends Service {

send

method
 Mailer.prototype.send() 

Option name Type Description
send(options, callback) {
	if (this._transporter === undefined) {
		console.log("Cannot send email as no transporter is defined");
		return;
	}
	if (!options.from) {
		options.from = this._params.sender;
	}
	var promise = Promise.resolve();
	if (options.template) {
		if (!options.replacements) {
			options.replacements = {};
		}
		options.replacements.now = new Date();
		let template = this._getTemplate(options.template);
		if(template) {
			promise = promise.then( () => {
				return template.render(options.replacements);
			}).then( (result) => {
				if (result.subject) {
					options.subject = result.subject;
				}
				if (result.html) {
					options.html = result.html;
				}
				if (result.text) {
					options.text = result.text;
				}
			});
		} else {
			throw Error("Unknown mail template");
		}
	}
	return promise.then( () => {
		return this._transporter.sendMail(options, callback)
	});
}