I have a Problem with the crontab function.
I wrote the following python Script that only sends an email, and it worked when i called it from the terminal with python mail_script.py
But when i tried to run it with crontab every minute, i received a mail from the email@example.com.
Code: Select all
import smtplib mailServer = 'pop.gmail.com' mailPort = 587 mailLogin = 'firstname.lastname@example.org' mailPass = 'password' mailSendFrom = mailLogin mailSendTo = [u]'email@example.com'[/u] mailTLS = True mailDebug = False def sendemail(from_addr, to_addr, subject, message): try: header = 'From: %s\n' % from_addr header+= 'To: %s\n' % to_addr header+= 'Subject: %s\n\n' % subject message = header + message conn = smtplib.SMTP(mailServer, mailPort) if mailDebug: conn.set_debuglevel(True) #show communication with the server if mailTLS: conn.starttls() conn.login(mailLogin, mailPass) error = conn.sendmail(from_addr, to_addr, message) if not error: print "Successfully sent email" except Exception, e: print "\nSMTP Error: " + str(e) finally: if conn: conn.quit() if __name__ == '__main__': sendemail(mailSendFrom, mailSendTo, 'hi', 'How are you?')
In that mail was written:
Delivery to the following recipient failed permanently:
Technical details of permanent failure:
DNS Error: Address resolution of raspberrypi. failed: Domain name not found
Know I am very confused.. the recepient of my python script is firstname.lastname@example.org, and not pi@raspberrypi.
So I don't know why the mail was tried to send to pi@raspberrypi when called the script with crontab?
The same happens, when I try to call another script with crontab, for example "helloworld.py". I get an email with the same error..
When I call the script in the terminal with python mail_script.py, everything is ok and the mail gets sended to email@example.com..