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

template directory in Firebase Functions #358

Closed jonathan-chin closed 5 years ago

jonathan-chin commented 5 years ago

I'm having template directory issues when executing from Firebase Functions. I'm guessing there's some conflict in the relative pathing. I have some basic code in a js file:

let aws = require('aws-sdk');
const Email = require('email-templates');
let nodemailer = require('nodemailer');
const path = require('path');

aws.config.update({
    accessKeyId: "[VALID ACCESS KEY",
    secretAccessKey: "[VALID SECRET]",
    region: "us-west-2"
});

let SEStransporter = nodemailer.createTransport({
    SES: new aws.SES({
        apiVersion: '2010-12-01'
    })
});

const email = new Email({
    message: {
    from: '[VALID EMAIL ADDRESS]'
    },
    send: true,
    preview: false,
    transport: SEStransporter
});

email
    .send({
    template: "block",
        message: {
        to: "[VALID EMAIL ADDRESS]"
        },
        locals: {}
    })
    .then(function(response){
      // ...
    })
    .catch(function(error){
      // ...
    });

When I run this from the command line (eg node test.js), it works perfectly. But when I put it into a Firebase Function function, I get:

info: Error: No content was passed for subject, html, text, nor attachments message props. Check that the files for the template "block" exist.
    at /Users/jon/Projects/sm/sma/server/functions/node_modules/email-templates/lib/index.js:264:167
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/jon/Projects/sm/sma/server/functions/node_modules/email-templates/lib/index.js:11:103)
    at _next (/Users/jon/Projects/sm/sma/server/functions/node_modules/email-templates/lib/index.js:13:194)

I've tried multiple variations of editing the views root but the problem persists: ok when running as a standalone script but 'does not exist' error when running in a Firebase Function

Exilz commented 4 years ago

@jonathan-chin did you solve this ? I'm facing the same issue running my code in AWS' elastic beanstalk.

EDIT : for anyone also struggling with this, my issue had nothing to do with this package. The problem I had was that I forgot to copy my template folder when creating the docker image I use to deploy my application in the cloud. Hence, why it worked locally, but not in AWS' environment.