質問

I'm with a problem that I don't know the cause.

I'm sending e-mails with Python and all emails are dated from 1970-01-01 01:00

Here is the code:

def send_email(self, host, port, username, password, frommail, tomail, subject, message):        
    msg = MIMEText(message)
    msg['Subject'] = subject
    msg['From'] = frommail
    msg['To'] = tomail
    s = smtplib.SMTP(host, port)
    s.login(username, password)
    s.sendmail(frommail, [tomail], msg.as_string())
    s.quit() 

I'm using Ubuntu 12.04, I've checked the system date and it is ok. Any ideas of what might be causing this?

Best Regards,

役に立ちましたか?

解決

You don't have a

msg['Date'] = ...

in your code.

Try

msg['Date'] = email.utils.formatdate(localtime=True)

for adding the send date. See here.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top