2

I am using smtplib to create a MIMEMultipart email and the result is a header that looks as follows.

MIME-Version: 1.0
Content-Type: multipart/alternative; charset="utf-8"; boundary="===============2613033831060434871=="
Content-Transfer-Encoding: base64
Subject: Your report is ready
From: no-reply@example.com
To: someone@example.com

Is this a valid e-mail header? Have experienced no complaints except for one person who is experiencing their e-mail being cut off before showing the body of the e-mail. They claim that it's because the Content-Type is appearing in the wrong place.

This is how the message was created

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from cl.library.htmlutils import html_to_text

def make_multipart_email(from_addr, to_addr, html, subject=None, text=None):
    text = text or html_to_text(html)
    msg = MIMEMultipart('alternative')
    msg.set_charset('utf8')
    msg['Subject'] = subject
    msg['From'] = from_addr
    msg['To'] = to_addr

    msg.attach(MIMEText(text, 'plain', 'UTF-8'))
    msg.attach(MIMEText(html, 'html', 'UTF-8'))

    return msg
snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
rayosunny
  • 21
  • 3

2 Answers2

1

According to RFC 5322

... header fields are not guaranteed to be in a particular order.

So your email is valid.

Community
  • 1
  • 1
snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
0

No, your email is not valid. It is missing the required Date: header.

The reference to this is in the very same reference provided by @snakecharmerb, https://www.rfc-editor.org/rfc/rfc5322.html#section-3.6

Douglas Held
  • 1,452
  • 11
  • 25