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

Emails are not being sent #305

Closed matiassequeira closed 6 years ago

matiassequeira commented 6 years ago

Hi, I'm having the problem that the app is not sending the email. May be a problem with the template engine? Above I write down the codes I'm using and the console output. I'd in providing any further details.

mailSender function has:

const transporter = nodemailer.createTransport({
    host: 'smtp.ethereal.email',
    port: 587,
    auth: {
        user: `${user}`,
        pass: `${password}`
    }
});

mailOptions.to= destinatioon
mailOptions.from= user;

 const email = new Email({
        message: mailOptions,
        transport: transporter,
        views: {
            root: '../templates/email',
            options: {
                extension: 'ejs'
            }
        }
    });

    email.send({
            template: 'resetPassword',
            locals: templateParamsArray
        })
        .then(console.log)
        .catch(console.error);

In app.js I have:

server.engine('html', require('ejs').renderFile);
server.set('view engine', 'ejs');

The templates directory: image

The templates:

html.ejs:

<tr>
    <td align="left" style="padding:0px 40px 40px 40px"><p
                style="color:#262626; font-size:32px; text-align:left; font-family: Verdana, Geneva, sans-serif">
            Hello <%= name %></p>
        <br style="color:#000000; font-size:16px; text-align:left; font-family: Verdana, Geneva, sans-serif; line-height:22px ">
        You requested for a password reset.</br>
        Please complete your password reset by clicking the below link</br>
        <a href="<%= token %>">
            <%= token %>
        </a> <br/>
        <br/>
        </p></td>

</tr>

subject.ejs:

=Password Reset

Console output: { envelope: server_1 | { from: 'abc@ethereal.email', server_1 | to: [ 'ms@provider.com' ] }, server_1 | messageId: 'themessageid@ethereal.email', server_1 | message: '{"to":[{"address":"ms@provider.com","name":""}],"from":{"address":"abc@ethereal.email","name":""},"attachments":[],"headers":{},"messageId":"abc@ethereal.email"}', server_1 | originalMessage: server_1 | { to: ' ms@provider.com', server_1 | from: 'ee4p6d6bz7p5fp6w@ethereal.email', server_1 | attachments: [] } }

niftylettuce commented 6 years ago

NODE_ENV=production flag being used? Or you can explicitly pass option send: true.

matiassequeira commented 6 years ago

Oh, my bad. I added the option send: true and it worked, but it didn't send the html nor the subject. Do you see any problem with the configuration of the template engine?

The output:

{ accepted: [ 'ms@provider.com' ],
server_1         |   rejected: [],
server_1         |   envelopeTime: 924,
server_1         |   messageTime: 323,
server_1         |   messageSize: 216,
server_1         |   response: '250 Accepted [STATUS=new MSGID=Ww9WnKs4vAoSta9BWxrn-ljdoAp1CdRYAAAADt5v.ACD0f09wEd7R.8nElg]',
server_1         |   envelope: 
server_1         |    { from: 'abc@ethereal.email',
server_1         |      to: [ 'ms@provider.com' ] },
server_1         |   messageId: '<id@ethereal.email>',
server_1         |   originalMessage: 
server_1         |    { to: '  ms@provider.com',
server_1         |      from: 'abc@ethereal.email',
server_1         |      attachments: [] } }

Thanks for your response.

matiassequeira commented 6 years ago

Hi, is there any way I can set email-templates package in "verbose mode"? So I can see where I'm getting the problem, because I can't send the html. I think it's a problem between email-templates and ejs.

Thanks

niftylettuce commented 6 years ago

Yes see the debug section in README

On Mon, Jun 11, 2018, 11:56 AM matiassequeira notifications@github.com wrote:

Hi, is there any way I can set email-templates package in "verbose mode"? So I can see where I'm getting the problem, because I can't send the html. I think it's a problem between email-templates and ejs.

Thanks

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/niftylettuce/email-templates/issues/305#issuecomment-396312014, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf7hS6A7b6Hh_oznIwe-Rph6upaoTypks5t7qFRgaJpZM4Ugn3S .

niftylettuce commented 6 years ago

I'm assuming you resolved this, but if not let me know

matiassequeira commented 6 years ago

Yes, it's solved. Thank you

El El mar, 31 jul. 2018 a las 20:12, niftylettuce notifications@github.com escribió:

I'm assuming you resolved this, but if not let me know

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/niftylettuce/email-templates/issues/305#issuecomment-409397488, or mute the thread https://github.com/notifications/unsubscribe-auth/ANsDjaxWfiqA0SWpl47lF7xPDnhxx612ks5uMORfgaJpZM4Ugn3S .

-- Ing. Matías Sequeira

Cel: +54 9 345 433 3664 Skype: matias-sequeira@hotmail.com Linkedin: linkedin.com/in/sequeiram/