我有如下所示的 python 代码。手动执行时效果很好。但是当通过 cronjob 执行时,电子邮件不会被发送。这是代码:
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())