I have an email template that is rendering certain datetime strings from django. I would like to render this time based on the user's timezone. To solve this I have opted to use momentjs
however once, it seems the javascript in the template is not run and anything wrapped in javascript doesn't appear in the email. Based from this answer https://stackoverflow.com/a/42056995/8513875 email clients don't include external css, I assume it's the same issue with javascript, how would I go about making this recognized.
Asked
Active
Viewed 539 times
0

oma0256
- 103
- 4
- 11
-
2Email clients will not load or run any JS. Your application would need to know the user's timezone before the email is sent and render the email using that timezone – Iain Shelvington Jul 19 '20 at 20:56
-
Is it possible to use something like https://github.com/roverdotcom/django-inlinecss as specified in this answer https://stackoverflow.com/a/42056995/8513875 or is this just available for css. – oma0256 Jul 19 '20 at 21:02
-
1Those packages convert CSS into inline `style` attributes on the generated HTML email. Decent email clients will __never__ support running JS attached to an email – Iain Shelvington Jul 19 '20 at 21:07
-
Ohh... right thank you @IainShelvington – oma0256 Jul 19 '20 at 21:10
-
1To specify why: JS can contain malicious code i.e. security risk – David Alford Jul 19 '20 at 23:32
-
@IainShelvington any suggestions on how I can determine a user's timezone for instance based on their email? – oma0256 Jul 20 '20 at 12:49
1 Answers
1
To expand on what @IainShelvington stated, and answer...
@oma0256 ... how I can determine a user's timezone...
... here's how to obtain the timezone offset via JavaScript (in browser) prior to generating the email...
const timezone = (new Date).getTimezoneOffset() / 60;
... note again, this will not run within an email, but instead should be used when generating the email from whatever template the service is using.
And regarding the second part of the question...
@oma0256 ... for instance based on their email?
... if you're fortunate that information will be within the email headers, however, such things (much like any other client-side supplied data) cannot be trusted.
Attribution

S0AndS0
- 860
- 1
- 7
- 20