发送电子邮件时主题未通过

Subject is not passing when sending email

我正在发送如下电子邮件:

def sendEmail(serial_number,date, time, latLon):

sender = serial_number+'@sdtr.com'
receivers = ['michael.grobman@station711.com']

msg = MIMEMultipart()
msg['From'] = sender
msg['To'] = receivers
msg['Subject'] = 'Hello!'
msg = MIMEText("""        
    GPS fix

    Lat: %s
    Long: %s
    Time: %s
    Date: %s
    Altitude:
    Velocity: 

    Accuracy
    Horiz: +/- 16 m
    Vert: +/- 32 m

    Please note your reply is limited to 160 Latin characters or approximately 135 for non-Latin characters.

    Sent via bla. The mobile satellite company
    """ % (latLon[0], latLon[1], time, date))


smtpObj = smtplib.SMTP('bla', 587)
smtpObj.ehlo()
smtpObj.login('bla', 'bal')
smtpObj.sendmail(sender, receivers, msg.as_string())
smtpObj.quit()
print("Successfully sent email")

问题是在接收方,header 没有附加主题, 我已经尝试了几种不同的方法来指导我发现但仍然没有主题的相同结果。

我仅使用 MIMEText 就设法获得了有效的电子邮件。此外,我添加了 2 个非常有趣的 headers(日期和 Message-ID):

from email.utils import make_msgid
from time import asctime


def sendEmail(serial_number, date, time, lat_lon):
    sender = serial_number + '@sdtr.com'
    receivers = ['michael.grobman@station711.com']

    message = """
GPS fix

Lat: %s
Long: %s
Time: %s
Date: %s
Altitude:
Velocity:

Accuracy
Horiz: +/- 16 m
Vert: +/- 32 m

Please note your reply is limited to 160 Latin characters or approximately 135 for non-Latin characters.

Sent via Inmarsat. The mobile satellite company
""" % (lat_lon[0], lat_lon[1], time, date)

    msg = MIMEText(message)
    msg['From'] = sender
    msg['To'] = ', '.join(receivers)
    msg['Subject'] = 'Hello!'
    msg['Message-ID'] = make_msgid()
    msg['Date'] = asctime()

    smtpObj = smtplib.SMTP('...', 587)
    smtpObj.login('...', '...')
    smtpObj.sendmail(sender, receivers, msg.as_string())
    smtpObj.quit()
    print('Successfully sent email')