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

Not sending emails using Nodemailer Transporter #311

Closed hanselabreu closed 6 years ago

hanselabreu commented 6 years ago

Hello guys, I ran into a little problem. My application doesn't seem to be sending the email when I submit the post. It is not giving me an error either.

Here is my code:

const nodemailer = require('nodemailer');
const Email = require('email-templates');

const transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: 'user',
        pass: 'password'
    }
});

const email = new Email({
        message: {
            from: 'hanzoanon@gmail.com'
        },
        send: true,
        preview: false,
        transport: transporter,
        views: {
            root: '../emails/templates',
            options: {
                extension: 'ejs'
            }
        }
    });

   email
        .send({
            template: 'templates',
            message: {
                to: user.email
            }
        })
        .then(console.log)
        .catch(console.error);

The catch returns null and then returns:

{ accepted: [ 'hansel2595@gmail.com' ],
  rejected: [],
  envelopeTime: 112,
  messageTime: 437,
  messageSize: 204,
  response: '250 2.0.0 OK 1532478538 z14-v6sm2567024uao.16 - gsmtp',
  envelope: { from: 'hanzoanon@gmail.com', to: [ 'hansel2595@gmail.com' ] },
  messageId: '<6eb759bd-b59a-e044-b13c-1966e651f432@gmail.com>',
  originalMessage: 
   { from: 'hanzoanon@gmail.com',
     to: 'hansel2595@gmail.com',
     attachments: [] } }

But the email does not go out.

When using the same transporter using just Nodemailer it works just fine.

Do you guys see any problems?

Thanks!

hanselabreu commented 6 years ago

Found what the problem was. I was wrongly setting the root of the templates. In the new version the root of the templates is ./emails.

niftylettuce commented 6 years ago

Great, thank you for the update!