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.64k stars 339 forks source link

[fix] DESCRIPTIVE TITLE #455

Closed queejie closed 8 months ago

queejie commented 9 months ago

Describe the bug

Node.js version: v16.20.0

OS version: MacOS Ventura 13.5.2 (22G91)

Description: Calls to email.send() never return or fire exception in dev mode, but email does get sent to browser.

Actual behavior

Calls to email.send() never return or fire exception in dev mode, but email does get sent to browser.

Expected behavior

Expect send() to either throw an exception or return a result. I turned debugging on via the environment variable, and no errors are reported there.

Code to reproduce

    public async send() {
        try {
            const emailConfig: EmailTemplate.EmailConfig = {
                message: {from: this.config.from},
                views: {root: this.config.templateDir + '/emails'},
                send: true,
                subjectPrefix: this.env.opMode !== 'production' ? `[${this.env.opMode.toUpperCase()}] ` : false,
            };
            emailConfig.transport = {sendmail: true};
            const email: EmailTemplate = new Email(emailConfig);
            console.log('SEND...');
            const result = await email.send({
                template: this.config.template,
                message: {to: this.config.to},
                locals: this.config.data
            });
            console.log('AFTER'); // Never gets here
            return result;
        } catch (exception: any) {
            return (`Unable to send email. code=${exception.code}`); // Never gets here
        }
    }

Checklist

titanism commented 9 months ago

Can you please create a GitHub repository with reproducible test case and then link it here?