首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >主题在发送电子邮件时不传递。

主题在发送电子邮件时不传递。
EN

Stack Overflow用户
提问于 2017-05-04 18:04:38
回答 1查看 55关注 0票数 0

我发一封电子邮件如下:

代码语言:javascript
复制
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")

问题是,在接收方,没有主题附加到标题,我已经尝试了几种不同的方式来引导,我已经找到了,但仍然没有主题相同的结果。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-04 19:22:29

我只使用MIMEText就成功地收到了一封有效的电子邮件。此外,我还添加了两个非常有趣的标题(日期和消息ID):

代码语言:javascript
复制
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')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43789884

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档