0
我有如下所示的python代碼。手動執行時,它工作正常。但是當通過cronjob執行時,電子郵件不會被髮送。下面是代碼:Python的smtplib定期工作,但不是在通過cron執行時不能運行
msg = MIMEMultipart()
msg['From'] = sender
msg['To'] = to
msg['Subject'] = subject
msg.attach(MIMEText(message))
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(login, password)
print mailServer.sendmail(login, to, msg.as_string())