I have python code that looks like below. It works fine when executed manually. But when executed via a cronjob, the email is not being sent. Here is the code:
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())