question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

promisify nodemailer-smtp-transport

See original GitHub issue

Hey, i try to get into bluebird. can you help me with wrapping nodemailer-smtp-transport? I am using koa and tried a lot but couldnt find the solution. Here is my code:

var nodemailer = require('nodemailer'); var smtpTransport = require('nodemailer-smtp-transport'); var Promise = require("bluebird");
exports.create = function*() {
  var transporter = nodemailer.createTransport(smtpTransport({
      host: 'smtp.myemailservice.de',
      port: 25,
      auth: {
          user: 'user',
          pass: 'pw'
      }
  }));

  var mailOptions = {
      from: 'Fred Foo ✔ <foo@blurdybloop.com>', // sender address
      to: 'email@email.com', // list of receivers
      subject: 'Hello ✔', // Subject line
      text: 'Hello world ✔', // plaintext body
      html: 'mail conent'·
  };

  transporter.sendMail(mailOptions, function(error, info) {
      if (error) {
          this.body = error;
      } else {
        this.body = info.response;
      }
  });

};

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ricardogracacommented, Mar 10, 2015

I was also having the same problem some time ago. The code above is no longer valid. You have to use this:

var nodemailer = require('nodemailer')
var transport = Promise.promisifyAll(nodemailer.createTransport({ /* options */ }))

Note that if you are trying to use a transport mechanism that is not built-in, there is a small difference. Instead of passing an options object to the createTransport method, you pass the external transport directly like so:

// Example using the stub transport
var stubTransport = require('nodemailer-stub-transport')()
var transport = Promise.promisifyAll(nodemailer.createTransport(stubTransport))
1reaction
wavdedcommented, Oct 1, 2014

nodemailer-smtp-transport is built-in to nodemailer (it’s the default transport) so you should need to install it separately. I typically only promisify the sendMail method:

var nodemailer = require('nodemailer')
var P = require('bluebird')

var transport = nodemailer(smtpTransportOpts)
var sendMail = P.promisify(transport.sendMail, transport)

sendMail(mailOpts)
  .then(handleRes)
  .catch(handleErr)

However you can promisify all the methods by using P.promisifyAll like such:

var transport = P.promisifyAll(nodemailer(smtpTransportOpts))

By default, bluebird gives the new promise aware methods Async suffixes so you’d use sendMail like this:

tranport.sendMailAsync(mailOpts)
  .then(handleRes)
  .catch(handleErr)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Promisify Nodemailer with bluebird? - Stack Overflow
This how I got it working (typescript, bluebird's Promise, nodemailer-smtp-transport): export const SendEmail = (from:string, to:string[], ...
Read more >
SMTP transport - Nodemailer
SMTP transport. SMTP is the main transport in Nodemailer ... You can verify your SMTP configuration with verify(callback) call (also works as a...
Read more >
nodemailer-smtp-transport JavaScript and Node.js ... - Tabnine
How to use nodemailer-smtp-transport. Best JavaScript code snippets using nodemailer-smtp-transport(Showing top 8 results out of 315).
Read more >
Nodemailer Service in Node.js using SMTP and xoauth2
Here, we will learn how to send a mail in Node.js using Nodemailer ... config')// create reusable transporter object using the default SMTP...
Read more >
How to use the nodemailer.createTestAccount function in ...
return new Promise((resolve, reject) => { // Generate test SMTP service account from ethereal.email // Only needed if you don't have a real...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found