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

Juice tries to find file of some inlined image #244

Closed zdila closed 7 years ago

zdila commented 7 years ago

In our mail templates we only use images stored on remote server (S3) and referenced with absolute URL. We often see following error in the logs:

Error: The file /project/dist/server/build/data:image/png;base64,iVBORw0KGgoAAAANSU...JRU5ErkJggg== was not found!
    at DataURI.encodeSync (/project/node_modules/datauri/api.js:102:11)
    at new DataURI (/project/node_modules/datauri/module.js:24:34)
    at Object.util.getFileReplacement (/project/node_modules/web-resource-inliner/src/util.js:184:24)
    at Object.replaceImg (/project/node_modules/web-resource-inliner/src/html.js:121:16)
    at /project/node_modules/async/dist/async.js:3853:24
    at eachOfArrayLike (/project/node_modules/async/dist/async.js:1003:9)
    at eachOf (/project/node_modules/async/dist/async.js:1051:5)
    at _parallel (/project/node_modules/async/dist/async.js:3852:5)
    at parallelLimit (/project/node_modules/async/dist/async.js:3935:5)
    at Object.module.exports [as html] (/project/node_modules/web-resource-inliner/src/html.js:254:5)
    at inlineExternal (/project/node_modules/juice/index.js:57:10)
    at Function.juiceResources (/project/node_modules/juice/index.js:74:3)
    at Promise (/project/node_modules/juice-resources-promise/index.js:7:11)
    at Promise (<anonymous>)
    at juiceResources (/project/node_modules/juice-resources-promise/index.js:6:10)
    at Promise (/project/node_modules/email-templates/index.js:177:32)

But sometimes the same template just works OK.

Versions:

zdila commented 7 years ago

I admit that it can be a bug in juice or web-resource-inliner it uses. Hopefully this will prevent it for us:

  juiceResources: {
    webResources: {
      images: false,
    },
  },
niftylettuce commented 7 years ago

This is due to #239 and https://github.com/niftylettuce/juice-resources-promise using juice which is not using the right version. I'm waiting on a patch version bump of juice in https://github.com/Automattic/juice/issues/279 so then I can use juice package directly vs. using my fork on GitHub.

niftylettuce commented 7 years ago

@zdila can you please try npm install --save email-templates@3.0.6?

niftylettuce commented 7 years ago

@zdila did you try latest version of email-templates? should be fixed. npm install email-templates@latest.

zdila commented 6 years ago

Now it doesn't error, but it removes src from img completely.

const email = new Email({
  message: {
    from: {
      name: No Reply,
      address: 'noreply@example.com',
    },
  },
  transport: nodemailer.createTransport(ses({ ...config.get('email.credentials') })),
  views: {
    options: {
      extension: 'ejs',
    },
  },
  htmlToText: false,
  juice: true,
  juiceResources: {
    preserveImportant: true,
  //   webResources: { // uncomment to keep `src`
  //    images: false,
  //  },
  },
});
niftylettuce commented 6 years ago

What version of juice and email-templates?

On Oct 23, 2017 3:57 AM, "Martin Ždila" notifications@github.com wrote:

Now it doesn't error, but it removes src from img completely.

const email = new Email({ message: { from: { name: No Reply, address: 'noreply@example.com', }, }, transport: nodemailer.createTransport(ses({ ...config.get('email.credentials') })), views: { options: { extension: 'ejs', }, }, htmlToText: false, juice: true, juiceResources: { preserveImportant: true, // webResources: { // uncomment to keep src // images: false, // }, }, });

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/niftylettuce/email-templates/issues/244#issuecomment-338577201, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf7hbVxX2VCSpcON7VND7R-c93X00m6ks5svEbTgaJpZM4Pr4cg .

zdila commented 6 years ago

"juice": "4.2.2" "email-templates": "3.1.5"

niftylettuce commented 6 years ago

Can you share any more info for me to reproduce the issue, such as a template and script to run? It'd be helpful if you even wrote a test that fails.

On Oct 23, 2017 4:00 AM, "Martin Ždila" notifications@github.com wrote:

"juice": "4.2.2" "email-templates": "3.1.5"

— You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub https://github.com/niftylettuce/email-templates/issues/244#issuecomment-338578136, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf7hb1uJ534MGa6BwBon4VGxQFYa8u7ks5svEe0gaJpZM4Pr4cg .