Tuesday, September 14, 2021

Instruct outlook to send a mail in future in a predetermined time using python(deferred delivery)

 import win32com.client as client
import datetime
outlook=client.Dispatch("Outlook.Application")
message=outlook.Createitem(0)
namespace=outlook.GetNameSpace('MAPI')
inbox=namespace.GetDefaultFolder(6)
message=inbox.items.add
message.To="allsourav@gmail.com;allsourav2@gmail.com"
message.CC="souravandamiya@gmail.com"
message.BCC="allsourav2@gmail.com"
message.Subject="Happy Birthday on 14.09.2021"
message.Body="Wish you a happy birthday ,\n learning outlook using python again"
message.Importance=2
message.ReadReceiptRequested=True
message.OriginatorDeliveryReportRequested=True
#message.DeferredDeliveryTime="15/09/2021 01:31:05 AM"
#cSendDate=datetime.date.today() #todays date
#cSendDate=(datetime.date.today() + datetime.timedelta (days=1)).strftime("%d-%m-%y") #tomorrows date
#cSendDate=datetime.datetime.now() + datetime.timedelta(days=1) #1 day from current datetime
cSendDate=datetime.datetime.now() + datetime.timedelta(minutes=2) #2 minutes from now
cSendDate=cSendDate.strftime("%d/%m/%Y %H:%M:%S %p") #formats the date like the outlook wants it in "15/09/2021 01:31:05 AM" in this format
print(cSendDate)
message.DeferredDeliveryTime=cSendDate

message.Save()
message.Display()
#message.Send()

No comments:

Post a Comment