rob-luke / emails-html-to-pdf

Convert emails without attachments to pdf and send as email
32 stars 7 forks source link

Fix issue 11 #12

Closed mirisbowring closed 2 years ago

mirisbowring commented 2 years ago

This PR fixes #11

This PR introduces 2 new Environment Variables:

HOSTS

This var is a semicolon separated list of hosts that should be added to /etc/hosts to prevent dns lookup failures. e.x.: HOSTS=127.0.0.1 tracking.paypal.com;127.0.0.1 my.custom.host.tld

WKHTMLTOPDF_OPTIONS

This var is a python dict (json) representation of wkhtmltopdf_options that can be passed to the used pdfkit library.

e.x.: WKHTMLTOPDF_OPTIONS='{"load-media-error-handling":"ignore"}'

More options for wkhtmltopdf can be found here. More about the usage of those options with pdfkit can be found here

Examples

I had the problem that the tracking pixel of PayPal caused a HostNotFoundError. This was because the container was not able to resolve the tracking.paypal.com domain.

With this PR, I would add following to the docker-compose.yml:


...
    environment:
        ...
        HOSTS=127.0.0.1 tracking.paypal.com
        WKHTMLTOPDF_OPTIONS={"load-media-error-handling":"ignore"}
rob-luke commented 2 years ago

This is brilliant. Thanks so much @mirisbowring

I'm away from my pc now. But I'll check this first thing in the morning.

@smseidl any chance you could review this one too?

rob-luke commented 2 years ago

Sorry this got away from me, I will look at this on the weekend and trial it locally.

rob-luke commented 2 years ago

@mirisbowring thanks for the PR. This works locally for me, so I will merge now. Thanks for the contribution.

I have a follow up question for you though, if I had a second tracking domain that was causing issues, how would I include that? Would the line become...?

...
    environment:
        ...
        HOSTS=127.0.0.1 tracking.paypal.com tracking.company.com
rob-luke commented 2 years ago

Ops I can see it in the first comment now, thanks