Python/Outlook 附件:"cannot find this file..verify exists"
Python/Outlook Attachment: "cannot find this file..verify exists"
我写了以下内容来使用 Outlook 发送电子邮件,但它无法找到我要引用的文件:
import win32com.client as win32
import glob
import os
import datetime
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'xx@ii.ca'
mail.Subject = 'Message subject'
mail.Body = 'Message body'
mail.HTMLBody = '<h2>HTML Message body</h2>'# this field is optional
#In case you want to attach a file to the email
newestfile = max(glob.iglob('*.csv'), key=os.path.getctime))
mail.Attachments.Add(newestfile)
mail.Send()
如果我尝试 print(max(glob.iglob('*.csv'), key=os.path.getctime)))
它 returns 正确的路径。直接在 newestfile
中写入路径也可以。为什么它没有以当前形式附加?
我也尝试过将路径转换为字符串,但没有用
来自 Attachments.Add Method (Outlook) 文档,第一个参数是:
The source of the attachment. This can be a file (represented by the
full file system path with a file name) or an Outlook item that
constitutes the attachment.
我写了以下内容来使用 Outlook 发送电子邮件,但它无法找到我要引用的文件:
import win32com.client as win32
import glob
import os
import datetime
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'xx@ii.ca'
mail.Subject = 'Message subject'
mail.Body = 'Message body'
mail.HTMLBody = '<h2>HTML Message body</h2>'# this field is optional
#In case you want to attach a file to the email
newestfile = max(glob.iglob('*.csv'), key=os.path.getctime))
mail.Attachments.Add(newestfile)
mail.Send()
如果我尝试 print(max(glob.iglob('*.csv'), key=os.path.getctime)))
它 returns 正确的路径。直接在 newestfile
中写入路径也可以。为什么它没有以当前形式附加?
我也尝试过将路径转换为字符串,但没有用
来自 Attachments.Add Method (Outlook) 文档,第一个参数是:
The source of the attachment. This can be a file (represented by the full file system path with a file name) or an Outlook item that constitutes the attachment.