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

Transport information #321

Closed sonnyk22 closed 6 years ago

sonnyk22 commented 6 years ago

Thank you for this great library.

My app works fine using the email-templates v2.7.1. Now, I want to use the latest version. I like the fact that in the latest version, I can send email with our requiring nodemailer. However, I am not sure where I can pass-in my transport information as example below.

{
    host: 'smtp.domain.net', 
    port: 465,
    secure: true,
    auth: {
        user: '',
        pass: ''
    }
}

Thank you!

niftylettuce commented 6 years ago

You pass it as the transport option https://github.com/niftylettuce/email-templates/blob/master/src/index.js#L83-L86.

sonnyk22 commented 6 years ago

Perfect! Thank you!

sonnyk22 commented 6 years ago

I more quick question.

I've gotten everything working nicely using the email-templates v5.0as seen in the code below, but every time an email gets send (I do received them in my inbox), the browser opens up and shows me the output of my template with all the fields set, and the text version of the same template. Is there a setting to turn this off in Developmentand Production?

Thank you!

const config = {
    views: {
        root: root,
        options: {
            extension: 'hbs'
        }
    },
    message: {
        from: constants.EmailFrom
    },
    send: true,
    transport: {
        host: emailCreds.host,
        port: emailCreds.port,
        secure: emailCreds.secure,
        auth: {
            user: emailCreds.auth.user,
            pass: emailCreds.auth.pass
        },
        tls: {
            rejectUnauthorized: false
        }
    }
}

const email = new Email(config);
email
    .send({
        template: constants.TplEmailConfirmation,
        message: {
            to: 'email@somthing.net'
        },
        locals: {
            name: 'me'
        }
    })
    .then(() => {
        // code
    })
    .catch((err) => {
        // code
    });
niftylettuce commented 6 years ago

The option is preview, see https://github.com/niftylettuce/email-templates/blob/master/src/index.js#L60. It will automatically be turned off in non-development environments.

On Wed, Sep 12, 2018, 10:11 PM Sonny K notifications@github.com wrote:

I more quick question.

I've gotten everything working nicely using the email-templates v5.0as seen in the code below, but every time an email gets send (I do received them in my inbox), the browser opens up and shows me the output of my template with all the fields set, and the text version of the same template. Is there a setting to turn this off in Developmentand Production ?

Thank you!

const config = { views: { root: root, options: { extension: 'hbs' } }, message: { from: constants.EmailFrom }, send: true, transport: { host: emailCreds.host, port: emailCreds.port, secure: emailCreds.secure, auth: { user: emailCreds.auth.user, pass: emailCreds.auth.pass }, tls: { rejectUnauthorized: false } } }

const email = new Email(config);

email .send({ template: constants.TplEmailConfirmation, message: { to: 'email@somthing.net' }, locals: { name: 'me' } }) .then(() => { // code }) .catch((err) => { // code });

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

sonnyk22 commented 6 years ago

That was it! Thank you!