Python Outlook - 向电子邮件添加日期
Python Outlook - Add date to email
我使用 python 脚本自动发送了一封 outlook 电子邮件。我现在想做的是在电子邮件正文中输入下周的日期。
是否有任何功能可以让我这样做?
例如,我想发送一封电子邮件,并在电子邮件中要求收件人在 4 月 29 日(从今天起整整一周)之前回复。有没有办法让我读取今天的日期,然后在电子邮件中打印出 7 天后的日期?
示例代码:
导入 win32com.client 作为客户端
导入路径库
将 pandas 导入为 pd
outlook = client.Dispatch('Outlook.Application')
#Mail item
message = outlook.CreateItem(0)
df = pd.read_excel(r'Desktop\Review.xlsx',index_col=False,sheet_name='Review', usecols = "A:H")
#Display message
body = df.to_html()
message.Display()
message.To = "Mick.callnan@something.com"
message.Subject = "Review"
message.HTMLBody = "Hi All, <br> <br>Please respond by this day next week **Enter date here**
#message.Send()
import datetime
# how many days allowance?
N = 7
# assign the deadline date
deadline = datetime.date.today() + datetime.timedelta(days=N)
# on its own, it already works...
print(f"Please respond by {deadline}.")
# prints out Please respond by 2021-04-29.
# but perhaps you want to format it
s = deadline.strftime("%d %b %Y")
print(f"Please respond by {s}.")
# prints out Please respond by 29 Apr 2021.
对了,格式代码请自行查看https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior。
我使用 python 脚本自动发送了一封 outlook 电子邮件。我现在想做的是在电子邮件正文中输入下周的日期。
是否有任何功能可以让我这样做?
例如,我想发送一封电子邮件,并在电子邮件中要求收件人在 4 月 29 日(从今天起整整一周)之前回复。有没有办法让我读取今天的日期,然后在电子邮件中打印出 7 天后的日期?
示例代码: 导入 win32com.client 作为客户端 导入路径库 将 pandas 导入为 pd
outlook = client.Dispatch('Outlook.Application')
#Mail item
message = outlook.CreateItem(0)
df = pd.read_excel(r'Desktop\Review.xlsx',index_col=False,sheet_name='Review', usecols = "A:H")
#Display message
body = df.to_html()
message.Display()
message.To = "Mick.callnan@something.com"
message.Subject = "Review"
message.HTMLBody = "Hi All, <br> <br>Please respond by this day next week **Enter date here**
#message.Send()
import datetime
# how many days allowance?
N = 7
# assign the deadline date
deadline = datetime.date.today() + datetime.timedelta(days=N)
# on its own, it already works...
print(f"Please respond by {deadline}.")
# prints out Please respond by 2021-04-29.
# but perhaps you want to format it
s = deadline.strftime("%d %b %Y")
print(f"Please respond by {s}.")
# prints out Please respond by 29 Apr 2021.
对了,格式代码请自行查看https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior。