Closed divramod closed 10 years ago
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)
I got it running. Thx for your hint.
@divramod can you please send the merge code.. i am facing the same issue
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))
@ricardograca i want to send mail and i am using the following code
var nodemailer = require('nodemailer'); nodemailer.SMTP = { host: 'mail.gmail.com', port: 25, use_authentication: true, user: my@example.com', pass: '***' };
var message = {
sender: "my@example.com",
to:'you@example.com',
subject: 'Test Report'
};
and the below code should return promise because i am using stackify module to execute in sync.
nodemailer.send_mail(message,
function(err) {
if (!err) {
console.log('Email send ...');
} else console.log(sys.inspect(err));
});
Do you have any solution for this??
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");
};