【问题标题】:Get data in email body with Python使用 Python 获取电子邮件正文中的数据
【发布时间】:2019-09-23 18:45:37
【问题描述】:

要自动执行一项任务,我需要在 Outlook 中通过电子邮件将代码发送给我,以便登录网站。我是 python 新手,所以我想知道如何使用 win32com 模块。

谢谢。

【问题讨论】:

  • 问题从一些你想要的代码开始,然后调试和改进,直到你有一个成品
  • 你能发一个电子邮件正文的例子吗?

标签: python outlook automation task win32com


【解决方案1】:

您可以使用 smtplib 和 email.MIME 库:

这是一个如何从/向 Outlook 电子邮件发送电子邮件的示例:

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText


strFrom = 'email@hotmail.com' 
strTo = 'email@hotmail.com'

msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = 'Email subject'
msgRoot['From'] = strFrom
msgRoot['To'] = strTo

msgAlternative = MIMEMultipart('alternative')
msgRoot.attach(msgAlternative)

body='text, can be plain or html'

msgText_Total=MIMEText(body,'html')
msgAlternative.attach(msgText_Total)

s = smtplib.SMTP('SMTP.Office365.com:587')
s.ehlo()
s.starttls()
s.login('email@hotmail.com','password')
s.sendmail(strFrom, msgRoot["To"].split(","), msgRoot.as_string())
s.quit()

希望对你有所帮助。

【讨论】:

    猜你喜欢
    • 2013-04-30
    • 2012-12-11
    • 2011-01-14
    • 1970-01-01
    • 2018-02-23
    • 2019-04-12
    • 1970-01-01
    • 1970-01-01
    • 2018-11-10
    相关资源
    最近更新 更多