Skip to content

Instantly share code, notes, and snippets.

@solace
Last active November 20, 2020 06:58
Show Gist options
  • Save solace/cb927e62ea8502d21895cd53e75edded to your computer and use it in GitHub Desktop.
Save solace/cb927e62ea8502d21895cd53e75edded to your computer and use it in GitHub Desktop.
Meteor: Extend default Email.send invocation

Use a non-SMTP mail method in Meteor

Requirements:

  • lodash (or underscore, you may need to change your _ functions to suit)
  • Meteor email package
Meteor.startup(function () {
  var sendEmail = _.bind(Email.send, Email);
  _.extend(Email, {
    send: function (options) {
      if (/* your custom mail method exists */) {
        /* your custom mail method, pull the options you need from `options` */
        console.log('CUSTOM MAIL METHOD');
      } else {
        /* use the SMTP method */
        console.log('DEFAULT MAIL METHOD');
        sendEmail(options);
      }
    }
  });
});
@nicooprat
Copy link

Seems to work, thanks for sharing! Note: this code is for server-side only.

Just missing another }); at the end ;)

@fabyeah
Copy link

fabyeah commented Nov 3, 2016

This is great! Thanks a lot!

@chasmfiend
Copy link

Saved me a huge headache, thank you for this

@sgelbart
Copy link

sgelbart commented Jun 2, 2017

Thank you!!!!

@odesey
Copy link

odesey commented Feb 4, 2018

Thanks for this, works great.

@Natas0007
Copy link

Awesomeness! Others apparently don't think this is possible! Well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment