Use python to operate outlook to send emails, the code is as follows:
import win32com.client as win32
receiver = "[email protected]" #收件人
outlook = win32.Dispatch("Outlook.Application")
mail = outlook.CreateItem(0) # 0: creat mail
print("收件人是:" + receiver)
mail.To = receiver #收件人
mail.Subject = "aa" #邮件主题
mail.Attachments.Add(r"D:\aa.docx") #添加附件
mail.Body= "test" #邮件正文
mail.Send()
print("邮件发送成功。")
The following warning pop-up window will always appear when the email is sent:
My personal guess is that it takes time to load the attachment when sending the email, so add a delay before send():
import win32com.client as win32
import time
receiver = "[email protected]" #收件人
outlook = win32.Dispatch("Outlook.Application")
mail = outlook.CreateItem(0) # 0: creat mail
print("收件人是:" + receiver)
mail.To = receiver #收件人
mail.Subject = "aa" #邮件主题
mail.Attachments.Add(r"D:\aa.docx") #添加附件
mail.Body= "test" #邮件正文
time.sleep(1)
mail.Send()
print("邮件发送成功。")