Python Forum

Full Version: Wrong or missing date format and time in mails
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In one MacOSX I found an issue with date and time while receiving mails from all my python scripts(in this case 2), where some are being received without any date, and others with a US format(month/day/year), not sure, and I want to use the day/month/year format, and others with wrong time. Seems to be almost random when it occurs.

For example in a webmail that I have installed in that server as well as thunderbird I notice this problem, and I have also different reception date and/or time in the same mail. In Gmail app from android, I dont have this issue at all, all dates and time are correct.

#server = smtplib.SMTP(mail_server,25)
server = smtplib.SMTP(mail_server,587)
server.starttls()
server.login(smtp_auth_name,smtp_auth_pass)
subject = '%s_BACKUP job success made on %s' %(backup_identifier,server_name)
message = 'Current Config:\n%s\nStart time: %s\nFinish time: %s\nTarget path: %s\n\nStatus: \n\n%s\n\nBackup has been done.' %(current_config,inicial_date.strftime("%d/%m/%y %H:%M:%S"),datetime.datetime.now().strftime("%d/%m/%y %H:%M:%S"),backup_folder,checkpoint)
message_structure = 'From: %s\nTo: %s\nSubject: %s\nDate: %s\n\n%s' 
%(sender,email_receivers,subject,datetime.datetime.now().strftime("%d/%m/%y %H:%M:%Ss"),message)             
server.sendmail(sender,email_receivers,message_structure)
server.quit()
logging.debug('Email notification as been send to: %s',email_receivers)
So seems that there is a problem with the atribution of date and time in mail clients, and my question is how can I use just the date and time from my mail server instead.

I know that there is the formatdate(localtime=True) but dont know how to setup to my current config. Sad
Before you handle with date and time you must be import them.
I am an beginner with python, just i don't know what you try to do,
but here is an code you must start with...

# Import datetime before you handle with this
from datetime import datetime

# Here your code
Is this the problem ?... but further... i can't help you.
I am learn python and i am pure beginner with this languale.

Try my code... maby this the problem.

Jamie.
(Aug-08-2017, 12:38 PM)JamieVanCadsand Wrote: [ -> ]Before you handle with date and time you must be import them.
I am an beginner with python, just i don't know what you try to do,
but here is an code you must start with...

# Import datetime before you handle with this
from datetime import datetime

# Here your code
Is this the problem ?... but further... i can't help you.
I am learn python and i am pure beginner with this languale.

Try my code... maby this the problem.

Jamie.

Thanks for the help Jamie but its not that simple, the library is not the problem ehehe =P. The problem here is that I want to use my server time date instead of each mail client who seems to be the problem, but I really dont know how to write that field in mail header through python.

So seems that I was able to bypass this problem by removing the Date field from:

message_structure = 'From: %s\nTo: %s\nSubject: %s\n\n%s' 
%(sender,email_receivers,subject,datetime.datetime.now().strftime("%d/%m/%y %H:%M:%Ss"),message)
Now seems that the date is added by the MTA, because it is the same in each email client. I think that the previous date format was not handled properly by the server, leading to this problem.

I forgot to say that I have been using that date format in one exchange server, and I didnt have any problem there, only in this Dovecot(MUA)+Postfix(MTA) server.
*Dovecot(MDA)