Include external stylesheets internally for email templates

Viewed 4354

I'm trying to craft some nice email templates for my site, but I'm having a conflict between my desire for well-crafted code and functionality.

My problem is that all of my email templates are formatted like standard templates:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet"...>
    </head>
    <body>
        Some stuff
    </body>
</html>

which displays just fine as a webpage, but in trying to send this as a formatted email, it's essentially just sending the Some stuff section, which means none of the formatting really makes it across.

My current emailing code looks like this:

message = Message(
    subject="Subject",
    html= render_template(
        'emails/confirmation_email.html',
        confirmation_code=confirmation.confirmation_code
    ),
    sender = ("sender", "sender@gmail.com")
)

I'm using Jinja2 templates and the Flask-Mail extension.

Basically, I really want to include these stylesheets in my email, but I really object to including everything in a style tag.

2 Answers
Related