在编写脚本之前,需要确保Outlook已经安装在您的计算机上,并打开了Outlook应用程序。
示例代码:
import win32com.client as win32
# create an outlook object
outlook = win32.Dispatch('outlook.application')
# create a mail item
mail = outlook.CreateItem(0)
# set mail properties
mail.To = 'example@example.com'
mail.Subject = 'Automated Email'
mail.Body = 'This is an automated email sent via Python'
# attach a file
attachment = "C:/examplefile.txt"
mail.Attachments.Add(attachment)
# send the mail
mail.Send()
在上面的示例中,首先使用Win32com客户端创建了Outlook对象。接下来,使用CreateItem方法创建了一个电子邮件。然后,将邮件的收件人、主题和正文等属性设置为所需的值。最后,使用Attachments方法获取附件,将文件的路径作为参数传递,并通过调用Send方法来发送电子邮件。
注意:在使用这个脚本之前,需要将电子邮件的收件人、主题、正文和附件的路径更改为你自己的信息。
上一篇:编写脚本以删除目录内容