2015-08-24 43 views
0

我正嘗試使用win32com在Outlook電子郵件正文中發送超鏈接到共享目錄。我不確定當程序運行時,我的路徑發生了什麼,使目錄顯示爲如下所示。Python win32com Outlook HTMLbody格式化目錄不正確

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 

文件路徑在電子郵件的出現: \ servername1pps \文件夾

回答

0

傢伙在我的工作能夠回答這個問題。

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的意思,但它的工作。也許有人可以解釋什麼是對我來說。可能是一個愚蠢的問題,但我真的不知道。

0

要回答第二個問題,「字符串前的r是什麼意思」,它表示一個原始字符串。爲了從另一個計算器頁面引用:

「的R表示該字符串將被視爲一個原始字符串,這意味着所有的轉義碼將被忽略」

所以,如果你比如有一個文件路徑文件夾名稱在單詞之間有空格時,您必須使用r前綴。例如:R 「C:\用戶file.txt的之間\ \ A010101 \桌面\空間」

請參閱有關將R前綴的問題頁: What does preceding a string literal with "r" mean?