[英]Using relative paths in Microsoft Outlook COM with win32com
I created a function to send email of my output using win32com.client
in a Ppython script. 我创建了一个函数, win32com.client
在Ppython脚本中使用win32com.client
发送输出的电子邮件。
app = win32com.client.Dispatch('Outlook.Application')
mail = app.CreateItem(0)
mail.Subject = 'Output file'
mail.Body = 'Output file'
mail.To = 'foo@bar.com'
attachment = 'E:\\python\\outputfile.xlsx'
mail.Attachments.Add(attachment)
mail.Send()
It works good but I have a small issue. 效果很好,但是我有一个小问题。 It finds the attachment only if I give the entire path. 仅当我给出整个路径时,它才会找到附件。 For example, 例如,
attachment='outputfile.xlsx'
or 要么
attachment="\\outputfile.xlsx"
causes the error 导致错误
4096, 'Microsoft Outlook', 'File name or directory name is not valid.' 4096,“ Microsoft Outlook”,“文件名或目录名无效”。
I want to make the code portable so that it could find the file from its own directory. 我想使代码可移植,以便可以从其自己的目录中找到文件。
最简单的方法是import os
并使用os.path.abspath('outputfile.xlsx')
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.