python - Error sending Email (Gmail) from crontab but works from Java class -


i got following code working if launch java class python script

script

/usr/bin/python /home/tripwire/email/notify.py 

java class

public static void main(string[] args) {         string = user_name;         string pass = password;         string[] = { recipient }; // list of recipient email addresses         string subject = "hotspots area detected";         string body = "bla bla bla...";           sendfromgmail(from, pass, to, subject, body);     }      private static void sendfromgmail(string from, string pass, string[] to, string subject, string body) {         properties props = system.getproperties();         string host = "smtp.gmail.com";         props.put("mail.smtp.starttls.enable", "true");         props.put("mail.smtp.host", host);         props.put("mail.smtp.user", from);         props.put("mail.smtp.password", pass);         props.put("mail.smtp.port", "587");         props.put("mail.smtp.auth", "true");          session session = session.getdefaultinstance(props);         mimemessage message = new mimemessage(session);          try {             message.setfrom(new internetaddress(from));             internetaddress[] toaddress = new internetaddress[to.length];              // array of addresses             for( int = 0; < to.length; i++ ) {                 toaddress[i] = new internetaddress(to[i]);             }              for( int = 0; < toaddress.length; i++) {                 message.addrecipient(message.recipienttype.to, toaddress[i]);             }              message.setsubject(subject);             message.settext(body);             transport transport = session.gettransport("smtp");             transport.connect(host, from, pass);             transport.sendmessage(message, message.getallrecipients());             transport.close();         }         catch (addressexception ae) {             ae.printstacktrace();         }         catch (messagingexception me) {             me.printstacktrace();         }     } 

but when call python script thru cron job following error in log:

mar 10 09:50:01 ubuntu-dashboard-service cron[3586]: (tripwire) cmd (/usr/bin/python /home/tripwire/email/notify.py) mar 10 09:50:06 ubuntu-dashboard-service cron[3584]: (cron) error (grandchild #3586 failed exit status 1) mar 10 09:50:07 ubuntu-dashboard-service sendmail[3589]: s2a6o643003589: from=tripwire, size=783, class=0, nrcpts=1, msgid=<201403100650.s2a6o643003589@ubuntu-dashboard-service.qf.org.qa>, relay=tripwire@localhost mar 10 09:50:07 ubuntu-dashboard-service sm-mta[3590]: s2a6o79o003590: from=<tripwire@ubuntu-dashboard-service.qf.org.qa>, size=1131, class=0, nrcpts=1, msgid=<201403100650.s2a6o643003589@ubuntu-dashboard-service.qf.org.qa>, proto=esmtp, daemon=mta-v4, relay=localhost [127.0.0.1] mar 10 09:50:07 ubuntu-dashboard-service sendmail[3589]: s2a6o643003589: to=tripwire, ctladdr=tripwire (1000/1000), delay=00:00:01, xdelay=00:00:00, mailer=relay, pri=30783, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=sent (s2a6o79o003590 message accepted delivery) mar 10 09:50:07 ubuntu-dashboard-service sm-mta[3592]: s2a6o79o003590: to=<tripwire@ubuntu-dashboard-service.qf.org.qa>, delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=121131, relay=ubuntu-dashboard-service.qf.org.qa. [10.153.33.140], dsn=4.0.0, stat=deferred: connection refused ubuntu-dashboard-service.qf.org.qa. 

email, python , java class , crontab seem work fine...so must in permission of sending email crontab. different?

i running whole thing on ubuntu 11.04.

thanks,

edit

added email part python directly in order avoid cronjob issues. works!

added email part python directly in order avoid cronjob issues. works!


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -