2016-05-04 00:10:46 +00:00
|
|
|
// Copyright IBM Corp. 2014,2016. All Rights Reserved.
|
|
|
|
// Node module: loopback
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2013-07-03 05:37:31 +00:00
|
|
|
/**
|
2014-10-15 07:07:30 +00:00
|
|
|
* Email model. Extends LoopBack base [Model](#model-new-model).
|
2014-10-06 17:15:26 +00:00
|
|
|
* @property {String} to Email addressee. Required.
|
|
|
|
* @property {String} from Email sender address. Required.
|
|
|
|
* @property {String} subject Email subject string. Required.
|
2014-10-10 11:49:21 +00:00
|
|
|
* @property {String} text Text body of email.
|
2014-10-06 17:15:26 +00:00
|
|
|
* @property {String} html HTML body of email.
|
2014-10-10 11:49:21 +00:00
|
|
|
*
|
|
|
|
* @class Email
|
2013-12-20 01:49:47 +00:00
|
|
|
* @inherits {Model}
|
2013-07-03 05:37:31 +00:00
|
|
|
*/
|
|
|
|
|
2016-06-07 14:48:28 +00:00
|
|
|
var g = require('strong-globalize')();
|
|
|
|
|
2014-10-10 11:49:21 +00:00
|
|
|
module.exports = function(Email) {
|
2013-12-20 01:49:47 +00:00
|
|
|
|
2014-10-10 11:49:21 +00:00
|
|
|
/**
|
|
|
|
* Send an email with the given `options`.
|
|
|
|
*
|
|
|
|
* Example Options:
|
|
|
|
*
|
|
|
|
* ```js
|
|
|
|
* {
|
|
|
|
* from: "Fred Foo <foo@blurdybloop.com>", // sender address
|
|
|
|
* to: "bar@blurdybloop.com, baz@blurdybloop.com", // list of receivers
|
|
|
|
* subject: "Hello", // Subject line
|
|
|
|
* text: "Hello world", // plaintext body
|
|
|
|
* html: "<b>Hello world</b>" // html body
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* See https://github.com/andris9/Nodemailer for other supported options.
|
|
|
|
*
|
|
|
|
* @options {Object} options See below
|
|
|
|
* @prop {String} from Senders's email address
|
|
|
|
* @prop {String} to List of one or more recipient email addresses (comma-delimited)
|
|
|
|
* @prop {String} subject Subject line
|
|
|
|
* @prop {String} text Body text
|
|
|
|
* @prop {String} html Body HTML (optional)
|
|
|
|
* @param {Function} callback Called after the e-mail is sent or the sending failed
|
|
|
|
*/
|
|
|
|
|
|
|
|
Email.send = function() {
|
2016-06-07 14:48:28 +00:00
|
|
|
throw new Error(g.f('You must connect the {{Email}} Model to a {{Mail}} connector'));
|
2014-10-10 11:49:21 +00:00
|
|
|
};
|
2013-12-20 01:49:47 +00:00
|
|
|
|
2014-10-10 11:49:21 +00:00
|
|
|
/**
|
|
|
|
* A shortcut for Email.send(this).
|
|
|
|
*/
|
|
|
|
Email.prototype.send = function() {
|
2016-06-07 14:48:28 +00:00
|
|
|
throw new Error(g.f('You must connect the {{Email}} Model to a {{Mail}} connector'));
|
2014-10-10 11:49:21 +00:00
|
|
|
};
|
|
|
|
};
|