首页 > 解决方案 > 使用 Python 发送 Outlook 电子邮件时如何编写消息?

问题描述

我想使用 Python 在 Outlook 中编写消息:

大家好,

请帮助跟进以下机会:
[插入 html 表格]

最好的, XXX

我已经尝试过,但格式看起来不对,例如“请帮助跟进以下机会”这句话没有出现在单独的行上

def Emailer(text, subject, recipient):
    import win32com.client as win32   
    outlook = win32.Dispatch('outlook.application')
    mail = outlook.CreateItem(0)
    mail.To = recipient
    mail.Subject = subject
    mail.HtmlBody = text
    mail.Display(True)

table = dummy.to_html()

Emailer('Hi everyone, \n\nPlease help follow up the following opportunities:'+table+'Best,\nXXX','PSE','XXX@gmail.com')

标签: pythonoutlook

解决方案


原来我需要使用 html 语法:

Emailer('Hi everyone, <br>Please help follow up the following opportunities:'+table+'Best,<br>XXX','PSE','XXX@gmail.com')

推荐阅读