简体   繁体   English

我正在尝试在 python 中使用 HTML img 标签发送邮件,但出现以下错误

[英]I'm trying to use HTML img tag in python to send a mail, but I'm getting the following error

    import win32com.client as win32
    outlook = win32.Dispatch('outlook.application')
    mail = outlook.CreateItem(0)
    mail.To = 'abc@gmail.com'
    mail.Subject = 'Test Mail'
    mail.Body = 'Test'
    mail.HTMLBody = '''<img src="C:\Users\tkakati\Desktop\Automated mail\books_read.png" alt="Plot 1">''' #this field is optional
mail.Send()

I've been trying to run this code but I'm getting the following error:我一直在尝试运行此代码,但出现以下错误:

(unicode error) 'unicodeescape' codec can't decode bytes in position 437-438: truncated \UXXXXXXXX escape

您需要转义src的单个\\ ,最简单的方法是使用字符串文字r

mail.HTMLBody = r'''<img src="C:\Users\tkakati\Desktop\Automated mail\books_read.png" alt="Plot 1">'''

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试使用Selenium 2与Python绑定,但我收到导入错误 - Trying to use Selenium 2 with Python bindings, but I'm getting an import error 我正在尝试使用python在ubuntu上安装django = 1.9,并且在管理员登录时遇到以下错误 - I'm trying to install django=1.9 on ubuntu using python and I'm getting the following errors for admin login 我正在尝试在 ubuntu 上的崇高文本中使用 python 上的 tkinter 但我一直收到错误 - I'm trying to use tkinter on python in sublime text on ubuntu but i keep getting a error Python - 我正在尝试向自己发送 email - Python - I'm trying to send an email to myself 我在 Bokeh 中尝试使用 ColumnDataSource 时遇到错误 - I'm getting and error trying to use ColumnDataSource in Bokeh 我正在尝试使用此 python 代码创建 wordcloud,但不断出现错误 - I'm trying to create a wordcloud with this python code, but keeps getting error 我正在尝试使用 pyplot.scatter() 但我收到无效的语法错误 - I'm trying to use pyplot.scatter() but I'm getting an invalid syntax error 我正在尝试使用 pip 安装 nltk,但不一定会出错,但我也不确定这意味着什么 - I'm trying to use pip to install nltk and I'm not necessarily getting an error but I'm also not sure what it means 我正在尝试使用python实现strassen的算法,但出现错误 - I'm trying to implement strassen's algorithm using python and I'm getting a error 我正在尝试标准化我的属性,但由于 Python 找不到它而出现标准缩放器错误 - I'm trying to standardize my attribute but I'm getting standard scaler error because Python can not find it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM