import win32com.client as win32
import schedule
import time
from datetime import datetime
# 设置收件人和邮件主题
# 邮件收件人
recipient_email = "邮箱"
# 邮件主题
subject = "Scheduled Email"
# 邮件内容
body = "This is a scheduled email sent from Python using Outlook."
# 邮件附件地址
attachment = r"附件路径"
# 创建一个 Outlook 应用程序对象
outlook = win32.Dispatch('Outlook.Application')
def send_email():
# 创建一个邮件对象
mail = outlook.CreateItem(0)
mail.To = recipient_email
# 获取当前时间
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
mail.Subject = subject+str(current_time)
mail.Body = body
# 添加一个附件
# mail.Attachments.Add(attachment)
# 发送邮件
mail.Send()
print(str(current_time)+"Email sent successfully")
# 每 1 分钟发送一次邮件
schedule.every(1).minutes.do(send_email)
while True:
schedule.run_pending()
time.sleep(1)
python程序-用outlook定时给指定邮箱发送邮件
于 2023-03-31 12:42:49 首次发布
该代码示例展示了如何使用Python的schedule库和win32com.client模块,每分钟定时向指定邮箱发送带有当前时间的邮件。邮件内容可以自定义,并且可以添加附件。
4190

被折叠的 条评论
为什么被折叠?



