Python Forum
Wrong or missing date format and time in mails
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wrong or missing date format and time in mails
#1
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
Reply
#2
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.
Reply
#3
(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.
Reply
#4
*Dovecot(MDA)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare current date on calendar with date format file name Fioravanti 1 128 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Date Time Series Help...Please spra8560 2 314 Feb-01-2024, 01:38 PM
Last Post: spra8560
  Python date format changes to date & time 1418 4 518 Jan-20-2024, 04:45 AM
Last Post: 1418
  Downloading time zone aware files, getting wrong files(by date))s tester_V 9 961 Jul-23-2023, 08:32 AM
Last Post: deanhystad
  Formatting a date time string read from a csv file DosAtPython 5 1,162 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,388 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Modifying a date format jehoshua 17 2,870 Oct-29-2022, 08:44 PM
Last Post: jehoshua
  What time format is this? wrybread 3 2,003 Jun-15-2022, 02:46 PM
Last Post: snippsat
  Date format error getting weekday value Aggie64 2 1,378 May-29-2022, 07:04 PM
Last Post: Aggie64
  Convert Date to another format lonesoac0 2 1,632 Mar-17-2022, 11:26 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020