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

Mails not sending, always showing previews #302

Closed Laurensdc closed 6 years ago

Laurensdc commented 6 years ago

I'm starting my backend with NODE_ENV=production DEBUG=email-templates node serverBoot.js. I keep getting redirected to a preview window with the email, instead of the email actually sending. Terminal is also not outputting any information.

gcfabri commented 6 years ago

Try set option send: true.

niftylettuce commented 6 years ago

@Laurensdc can you please share code from serverBoot.js?

According to src/index.js it should automatically send and should also automatically stop the previews in non-development environments. My guess is that your NODE_ENV is somehow getting defaulted or overridden?

https://github.com/niftylettuce/email-templates/blob/master/src/index.js#L57-L58

gcfabri commented 6 years ago

A not related question, how to set a different path of the templates? I just tried to use views: { root: path.join(__dirname, '..', 'server', 'emails') } and it is just ignored.

ghost commented 6 years ago

I was having issues getting mail to send as well. Here's what worked for me:

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

            let transporter = nodemailer.createTransport({
                sendmail: true,
                newline: 'unix',
                path: '/usr/sbin/sendmail'
            });

            const email = new Email({
                message: {
                    from: config.emailFrom
                },
                send: true,
                transport: transporter,
                //textOnly: true,
                preview: false,
            });

            email
                .send({
                    template: 'ads_found',
                    message: {
                        to: config.emailTo
                    },
                    locals: {
                        ads: adsToEmail
                    }
                })
                .then(console.log)
                .catch(console.error);
niftylettuce commented 6 years ago

I'm assuming you guys all solved your issues?

If you still have problems, you can run your app with DEBUG=email-templates or DEBUG=* before it, e.g. DEBUG=* node app.js.

Let me know if we can be of more help in debugging!