diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/email.js | 35 | ||||
-rw-r--r-- | lib/sendgrid.js | 70 |
2 files changed, 2 insertions, 103 deletions
diff --git a/lib/email.js b/lib/email.js index ef4a3c4..d84e8a1 100644 --- a/lib/email.js +++ b/lib/email.js @@ -239,37 +239,6 @@ Email.prototype.toWebFormat = function() { return web; }; -/** - * This method returns the email object is a format to be consumed by the SendGrid.smtp - * using the smtp api - * - * @see SendGrid.smtp - */ -Email.prototype.toSmtpFormat = function() { - var smtp = { - to : this.to, - sender : this.from, - subject : this.subject, - body : this.text, - html : this.html, - reply_to : this.replyto, - headers : this.headers - }; - - if (this.bcc) { smtp.bcc = this.bcc; } - if (this.toname) { smtp.to = [this.toname, " <", smtp.to, ">"].join(""); } - if (this.fromname) { smtp.sender = [this.fromname, " <", smtp.sender, ">"].join(""); } - - smtp.headers['x-smtpapi'] = this.smtpapi.toJson(); - - this._formatFilesForNodeMailer(this.files); - - this.updateMissingTo(smtp); - smtp.attachments = this.files; - - return smtp; -}; - Email.prototype._formatFilesForNodeMailer = function(files) { var self = this; if (files && files.length > 0) { @@ -299,9 +268,9 @@ Email.prototype._formatFileForNodeMailer = function(file) { /** * There needs to be at least 1 to address, or else the mail won't send. - * This method modifies the data that will be sent via either Rest or SMTP. + * This method modifies the data that will be sent via either Rest * - * @param {object} data The data parameter to send via Rest or SMTP + * @param {object} data The data parameter to send via Rest */ Email.prototype.updateMissingTo = function(data) { if (this.smtpapi.to && this.smtpapi.to.length > 0) { diff --git a/lib/sendgrid.js b/lib/sendgrid.js index 637b6a2..96126b9 100644 --- a/lib/sendgrid.js +++ b/lib/sendgrid.js @@ -1,7 +1,6 @@ "use strict"; var package_json = require('./../package.json'); -var nodemailer = require('nodemailer'); var _ = require('lodash'); var request = require('request'); var Email = require('./email'); @@ -18,11 +17,6 @@ var Sendgrid = function(api_user, api_key, options) { this.options.port = this.options.port || 587; var send = function() { - if ( _this.options.api === 'smtp') { - smtp.apply(this, arguments); - return true; - } - web.apply( this, arguments ); }; @@ -45,34 +39,6 @@ var Sendgrid = function(api_user, api_key, options) { }.bind(this); /* - * Sends an email via SMTP and returns true if the - * message was sent successfully. - * - * @param {Email|Object} email An email object or a hash that has - * the values for the email to be sent. - * @param {Object} nodeMailerOptions Extra options for nodeMailer. i.e. Message-Id - * This parameter is optional. - * @param {Function} callback A function to call when the processing is done. - * This parameter is optional. - */ - var smtp = function(email, nodeMailerOptions, callback) { - - // Support a callback without nodeMailerOptions - if (! callback && typeof nodeMailerOptions === "function") { - callback = nodeMailerOptions; - nodeMailerOptions = null; - } - - var callback = callback || function() { }; - - if (email.constructor !== Email) { - email = new Email(email); - } - - _sendSmtp(email, nodeMailerOptions, callback); - }; - - /* * Psuedo-private methods */ var _sendWeb = function(email, callback) { @@ -135,51 +101,15 @@ var Sendgrid = function(api_user, api_key, options) { } }; - var _sendSmtp = function(email, nodeMailerOptions, callback) { - // SMTP settings - var smtp_settings = { - host: "smtp.sendgrid.net", - port: parseInt(_this.port, 10), - requiresAuth: true, - auth: { - user: api_user, - pass: api_key - } - }; - - if (smtp_settings.port == 465) { - smtp_settings['secureConnection'] = true; - } - - var smtpTransport = nodemailer.createTransport(_this.SMTP, smtp_settings); - - var smtpParams = email.toSmtpFormat(); - - if (_.isObject(nodeMailerOptions)) { - _.extend(smtpParams, nodeMailerOptions); - } - - smtpTransport.sendMail(smtpParams, function(error, response) { - - smtpTransport.close(); - if(error) { return callback(new Error(error.message), null);} - - return callback(null, {'message': 'success'}); - }); - }; - - /* * Expose public API calls */ this.version = package_json.version; - this.SMTP = "SMTP"; this.Email = Email; this.SmtpapiHeaders = SmtpapiHeaders; this.api_user = api_user; this.api_key = api_key; this.web = web; - this.smtp = smtp; this.send = send; this.options = this.options; this.port = this.options.port; |