Python Forum
email Library: properly send message as quoted-printable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
email Library: properly send message as quoted-printable
#1
I am struggling to get email clients to properly render HTML messages. I believe it is a result of the content transfer encoding. I've tried several different HTML code styles, using the net extensively. Nothing permits an email client to render HTML properly (I get the code in the message). Here's my code:
def create_message(sndr, rcvr, subj, body, extra=None):
    """

    @type sndr: str
    @type rcvr: str
    @type subj: str
    @type body: tuple
    @type extra: tuple
    @return: bytes
    """
    msg = message.EmailMessage()
    if '<' in sndr:
        name, sep, addr = sndr.rpartition(' ')  # Partition at space between display name & address
        name = name.strip()  # Remove leading and trailing spaces
        addr = addr.strip('<>')  # Remove leading and trailing angle brackets
        msg['From'] = headerregistry.Address(display_name=name, addr_spec=addr)
    else:
        msg['From'] = headerregistry.Address(display_name='', addr_spec=sndr)
    if '<' in rcvr:
        name, sep, addr = rcvr.rpartition(' ')
        name = name.strip()
        addr = addr.strip('<>')
        msg['To'] = headerregistry.Address(display_name=name, addr_spec=addr)
    else:
        msg['To'] = headerregistry.Address(display_name='', addr_spec=rcvr)
    msg['Subject'] = subj
    msg.set_content(body[0], charset='utf-8')
    msg.add_alternative(body[1], cte='quoted-printable')
    return msg.as_bytes()
The above is in the middle of things, but it's not working at the time of this post. NOTE: I don't want to use the legacy email API. All you can do with the legacy, you can do with the current. I've seen several SO posts, but they all use the legacy API as they are old posts (ca 10 years).

To sum up, all HTML messages are displaying as raw code. My HTML is solid, I'm at the point now where I just copy and pasted a working email. My problem is something in the transfer, and I think it's the content transfer encoding and encoding the email properly. But, whatever the problem is, I want to fix it.
Reply


Messages In This Thread
email Library: properly send message as quoted-printable - by malonn - Nov-14-2022, 11:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  smtplib send email has no timestamp Pedroski55 2 177 Jun-11-2024, 04:57 AM
Last Post: Pedroski55
  Send email with smtp without using Mimetext mgallotti 0 781 Feb-01-2023, 04:43 AM
Last Post: mgallotti
  how to check if someone send a message in a discord channel? Zerolysimin 1 867 Nov-06-2022, 11:10 AM
Last Post: Larz60+
  Unable to send email attachments cosmarchy 7 2,804 Mar-09-2022, 09:29 PM
Last Post: bowlofred
  How to make scraper send email notification just once themech25 0 1,459 Nov-08-2021, 01:51 PM
Last Post: themech25
  is this Unicode printable? Skaperen 2 1,519 Sep-23-2021, 01:25 AM
Last Post: Skaperen
  send email smtp rwahdan 0 1,860 Jun-19-2021, 01:28 AM
Last Post: rwahdan
  Bluetooth send message after connecting? korenron 2 2,754 Apr-26-2021, 05:50 AM
Last Post: korenron
  Need Outlook send email code using python srikanthpython 3 8,569 Feb-28-2021, 01:53 PM
Last Post: asyswow64
  How to send email using python? Gigux 2 2,955 Jul-04-2020, 07:53 AM
Last Post: Gigux

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020