Changeset 1829fbf in OpenWorkouts-current for ow/mail.py


Ignore:
Timestamp:
Feb 20, 2019, 9:31:22 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current, feature/docs, master
Children:
38171c6
Parents:
42d775c
Message:

(#61) Several fixes for the multipart/alternative (text+html) version of the verify
your account email:

  • Use premailer [1] to embed all styles into the body of the html part of the email (ensuring the styles are rendered correctly in most email clients)
  • Fixed some styles (RGB colors, transparencies, etc don't work in mail clients)
  • Ensure the different bodies (text and html) have the proper content type and charset set.

[1] https://pypi.org/project/premailer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/mail.py

    r42d775c r1829fbf  
    22
    33from pyramid_mailer import get_mailer
    4 from pyramid_mailer.message import Message
     4from pyramid_mailer.message import Message, Attachment
    55from pyramid.renderers import render
    66from pyramid.i18n import TranslationStringFactory
     7
     8import premailer
    79
    810_ = TranslationStringFactory('OpenWorkouts')
     
    4547    mailer = get_mailer(request)
    4648    txt_body = render(txt_template, context, request)
    47     html_body = render(html_template, context, request)
     49    html_body = premailer.transform(render(html_template, context, request))
    4850    message = Message(
    4951        subject=subject,
    5052        recipients=[user.email],
    51         body=txt_body,
    52         html=html_body
     53        body=Attachment(data=txt_body,
     54                        content_type="text/plain; charset=utf-8",
     55                        transfer_encoding="quoted-printable"),
     56        html=Attachment(data=html_body,
     57                        content_type="text/html; charset=utf-8",
     58                        transfer_encoding="quoted-printable")
    5359    )
    5460    message = idna_encode_recipients(message)
Note: See TracChangeset for help on using the changeset viewer.