I created a function to send email of my output using win32com.client
in a Ppython script.
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.'
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')
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.