python - Sending mail via smtplib loses time -
i want send status mail once day using cron job using smtplib.
sending of mail works well, sending time , date seems time , date when read mail, not when mail sent. may 6 hours later.
i have not found hints on providing sending time smtplib, message data. missing or problem mail server configuration? however, other mails handed in via thunderbird not show effect account.
my python program (with login data removed) listed below:
import smtplib sender = 'abc@def.com' receivers = ['z@def.com'] message = """from: sender <abc@def.com> to: receiver<z@def.com> subject: testmail hello world. """ try: smtpobj = smtplib.smtp('mailprovider.mailprovider.com') smtpobj.sendmail(sender, receivers, message) print "successfully sent email" except smtpexception: print "error: unable send email"
[edit]
code using email package suggested, still time shown in inbox reading time , not sending time.
import smtplib email.mime.text import mimetext sender = .. receiver = .. message = "hello world" msg = mimetext(message) msg['subject'] = 'testmessage' msg['from'] = sender msg['to'] = receiver try: s = smtplib.smtp(..) s.sendmail(sender, receiver, msg.as_string()) s.quit() print "successfully sent email" except smtpexception: print "error: unable send email"
you might have specify more information in headers of message. try using email
module build message instead of assembling text yourself.
Comments
Post a Comment