diff --git a/lib/index.js b/lib/index.js index 751ab46..2a0496f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -7,10 +7,13 @@ var _sendgrid2 = _interopRequireDefault(_sendgrid); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var SimpleSendGridAdapter = function SimpleSendGridAdapter(mailOptions) { - if (!mailOptions || !mailOptions.apiKey || !mailOptions.fromAddress) { - throw 'SimpleSendGridAdapter requires an API Key.'; + if (!mailOptions || !mailOptions.apiKey && !mailOptions.username && !mailOptions.password) { + throw 'SimpleSendGridAdapter requires an apiKey or username / password'; } - var sendgrid = (0, _sendgrid2.default)(mailOptions.apiKey); + if (!mailOptions.fromAddress) { + throw 'SimpleSendGridAdapter requires fromAddress'; + } + var sendgrid = mailOptions.apiKey ? (0, _sendgrid2.default)(mailOptions.apiKey) : (0, _sendgrid2.default)(mailOptions.username, mailOptions.password); var sendMail = function sendMail(_ref) { var to = _ref.to; diff --git a/src/index.js b/src/index.js index 68f584c..008f424 100644 --- a/src/index.js +++ b/src/index.js @@ -1,10 +1,13 @@ import SendGrid from 'sendgrid'; let SimpleSendGridAdapter = mailOptions => { - if (!mailOptions || !mailOptions.apiKey || !mailOptions.fromAddress) { - throw 'SimpleSendGridAdapter requires an API Key.'; + if (!mailOptions || (!mailOptions.apiKey && !mailOptions.username && !mailOptions.password)){ + throw 'SimpleSendGridAdapter requires an apiKey or username / password'; } - let sendgrid = SendGrid(mailOptions.apiKey); + if (!mailOptions.fromAddress){ + throw 'SimpleSendGridAdapter requires fromAddress'; + } + let sendgrid = (mailOptions.apiKey ? SendGrid(mailOptions.apiKey) : SendGrid(mailOptions.username, mailOptions.password)); let sendMail = ({to, subject, text}) => { return new Promise((resolve, reject) => {