Python win32com Outlook HTMLbody formatting directory incorrectly

2024-04-28 04:52:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在Outlook电子邮件的正文中使用win32com发送到共享目录的超链接。当程序运行时,我不确定我的路径发生了什么,它使目录显示为下面的样子。在

import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'EMAIL ADDRESSES'
mail.Subject = 'Subject'
mail.HTMLbody = ("Hello All -<br><br>"
         "Please find the following files in the shared drive:<br>"
         "<a href='\\servername1\apps\folder'>"
         "\\servername1\apps\folder</a><br><br>"
         "The file names are:<br>"
         "FILENAMES")
mail.send

文件路径在电子邮件中显示为: \服务器名称1pps\文件夹


Tags: appsthebr路径目录程序运行电子邮件mail
2条回答

我工作的人能回答这个问题。在

import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'EMAIL ADDRESSES'
mail.Subject = 'Subject'
mail.HTMLbody = (r"""Hello All -<br><br>
     Please find the following files in the shared drive:<br>
     <a href='\\servername1\apps\folder'>
     \\servername1\apps\folder</a><br><br>
     The file names are:<br>
     FILENAMES""")
mail.send

我们加上了“r”,然后加上了三个引号,这就奏效了。在

不知道r是什么意思,但它起作用了。也许有人能向我解释r是什么。可能是个愚蠢的问题,但我真的不知道。在

要回答第二个问题,“字符串前面的r是什么意思”,它表示原始字符串。要引用另一个stackoverflow页面:

r表示字符串将被视为原始字符串,这意味着所有转义码都将被忽略

因此,如果你有一个文件路径,其中文件夹名称在单词之间有空格,你就必须使用r前缀。例如:r“C:\Users\A010101\Desktop\Space between\文件.txt““

请参阅有关r前缀的问题页: What does preceding a string literal with "r" mean?

相关问题 更多 >