Saturday 15 September 2012

android - Sending an email using javamail without user interaction - java.net.ConnectException -



android - Sending an email using javamail without user interaction - java.net.ConnectException -

hello attempting create android application sends emails without need user interaction (the user informed of emails beingness sent). using javamail: http://code.google.com/p/javamail-android/downloads/list , next example: http://www.jondev.net/articles/sending_emails_without_user_intervention_%28no_intents%29_in_android getting next errors:

10-07 09:23:10.373: e/mailapp(9173): not send email 10-07 09:23:10.373: e/mailapp(9173): javax.mail.messagingexception: not connect smtp host: localhost, port: 25; 10-07 09:23:10.373: e/mailapp(9173): nested exception is: 10-07 09:23:10.373: e/mailapp(9173): java.net.connectexception: failed connect localhost/127.0.0.1 (port 25): connect failed: econnrefused (connection refused) 10-07 09:23:10.373: e/mailapp(9173): @ com.sun.mail.smtp.smtptransport.openserver(smtptransport.java:1391) 10-07 09:23:10.373: e/mailapp(9173): @ com.sun.mail.smtp.smtptransport.protocolconnect(smtptransport.java:412)

code sending email:

thread emailsendthread = new thread(new runnable() { @override public void run() { while (true) { seek { thread.sleep(100); } grab (interruptedexception e1) { // todo auto-generated grab block e1.printstacktrace(); } if (sendemail == true) { seek { mailsender m = new mailsender("firstname.surname@gmail.com", "password"); string[] toarr = {"example@email.com"}; m.setto(toarr); m.setfrom("firstname.surname@gmail.com"); m.setsubject("this email sent using mail service javamail wrapper android device."); m.setbody("email body."); seek { m.send(); if(m.send()) { toast.maketext(mainactivity.this, "email sent successfully.", toast.length_long).show(); } else { toast.maketext(mainactivity.this, "email not sent.", toast.length_long).show(); } } catch(exception e) { //toast.maketext(mailapp.this, "there problem sending email.", toast.length_long).show(); log.e("mailapp", "could not send email", e); } } grab (exception e) { log.e("email", "error", e); } seek { thread.sleep(100); } grab (interruptedexception e) { // todo auto-generated grab block e.printstacktrace(); } sendemail = false; } } } });

i have substituted email username , password illustration ones in code. send email execute sendemail = true;

you can send mails using smtp server. if smtp server not @ device running application, need provide address of smtp can send email. expected application not send email if smtp details not correct.

android email gmail javamail javax.mail

No comments:

Post a Comment