forwardemail / email-templates

Create, preview (browser/iOS Simulator), and send custom email templates for Node.js. Made for @forwardemail, @ladjs, @cabinjs, @spamscanner, and @breejs.
https://forwardemail.net/docs/send-emails-with-node-js-javascript
MIT License
3.67k stars 337 forks source link

Get email body after send #299

Closed felipe-pereira closed 6 years ago

felipe-pereira commented 6 years ago

Hi, I'm using the lib like this:

emailSender
    .send({
        template: 'forgotPassword',
        message: {
            to: email, subject: 'Password Reset'
        },
        locals: {
            name: name, token: tokenUrl
        }
    })
    .then(cb)
    .catch(cb);

For testing purposes I would like to check that the generated email html has the token, so I need the render result passed to cb

I checked what's returned there and got this (no what I need):

{ accepted: [ 'to@email.com' ],
  rejected: [],
  envelopeTime: 1087,
  messageTime: 1033,
  messageSize: 1365,
  response: '250 2.0.0 OK ---------uah.42 - gsmtp',
  envelope: { from: 'from@email.com', to: [ 'to@email.com' ] },
  messageId: '<-----------------------@email.com>' }

How can I get the email body there? (I only need it when env is test, so using a flag for this would be great)

niftylettuce commented 6 years ago

Yeah I agree this would be amazing to have - let me take a look here

niftylettuce commented 6 years ago

I filed an issue with Nodemailer (the core package we use) here, but I will patch in the interim for you. One moment.

niftylettuce commented 6 years ago

Please install v3.6.1 of email-templates for support via npm install email-templates@latest or yarn add email-templates@latest. I've provided documentation for how to get access to the message rendered (see Inspect Message under the Debugging section in the README).

cc @felipe-pereira

felipe-pereira commented 6 years ago

Superb!, I'll try it, thanks.