I'm sending automated messages from my local system using python mailer package. The mail automatically shows received time as UTC instead of EST. How to send emails using mailer with local time as received time.
import mailer
message = mailer.Message()
message.From = "[email protected]"
message.To = "[email protected]
message.CC = MsgCC
message.Subject = "Subject"
message.Body = "Message to send"
try:
sender = mailer.Mailer('smtp.com')
sender.send(message)
except:
print ('Error in sending email.')
Note: The program runs in Windows server 2008, Python version 3.6.3
The mailer uses time.gmtime()
to convert the current timestamp to UTC if you have not provided a timestamp.
You can try handing over your current local time as follows:
import time
import mailer
message = mailer.Message()
# Get current time and parse in your local time zone.
message.Date = time.strftime("%a, %d %b %Y %H:%M:%S %z", time.localtime())
message.From = "[email protected]"
message.To = "[email protected]"
message.Subject = "Subject"
message.Body = "Message to send"
try:
sender = mailer.Mailer('smtp.example.com')
sender.send(message)
except:
print ('Error in sending email.')