java - android sending email from app no longer working -
i used this tutorial send emails inside app. used same code 3 different apps , worked well. now, few months later, stopped working. have searched possible sites, none of them helped me. tried setting lower security gmail account , changing properties session, nothing worked. appreciate help.
log.d("emailsender","sending message"); properties props = new properties(); props.put("mail.smtp.host", host); props.put("mail.smtp.socketfactory.port", "465"); props.put("mail.smtp.socketfactory.class", "javax.net.ssl.sslsocketfactory"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "465"); session session = session.getdefaultinstance(props, new javax.mail.authenticator() { protected passwordauthentication getpasswordauthentication() { return new passwordauthentication(user,pass); } }); try { message message = new mimemessage(session); message.setfrom(new internetaddress(user)); message.setrecipients(message.recipienttype.to, internetaddress.parse(sharedpreferenceutils.getuseremail(getactivity()))); message.setsubject(subject); message.setcontent(content, "text/html; charset=utf-8"); //transport.send(message); transport transport = session.gettransport("smtps"); transport.connect (host, integer.parseint(port), user, pass); transport.sendmessage(message, message.getallrecipients()); transport.close(); log.d("emailsender", "message sent"); } catch (messagingexception e) { e.printstacktrace(); throw new runtimeexception(e); }
my error:
java.net.connectexception: failed connect smtp.gmail.com/2a00:1450:4013:c01::6d (port 465) after 90000ms: isconnected failed: enetunreach (network unreachable) @ com.sun.mail.smtp.smtptransport.openserver(smtptransport.java:1391) @ com.sun.mail.smtp.smtptransport.protocolconnect(smtptransport.java:412) @ javax.mail.service.connect(service.java:288) @ com.mihaela.myapp.ui.dialog.enterpassworddialog$sendmailtask.doinbackground(enterpassworddialog.java:222) @ com.mihaela.myapp.ui.dialog.enterpassworddialog$sendmailtask.doinbackground(enterpassworddialog.java:179) @ android.os.asynctask$2.call(asynctask.java:288) @ java.util.concurrent.futuretask.run(futuretask.java:237) @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:818) caused by: java.net.connectexception: failed connect smtp.gmail.com/2a00:1450:4013:c01::6d (port 465) after 90000ms: isconnected failed: enetunreach (network unreachable) @ libcore.io.iobridge.isconnected(iobridge.java:267) @ libcore.io.iobridge.connecterrno(iobridge.java:191) @ libcore.io.iobridge.connect(iobridge.java:127) @ java.net.plainsocketimpl.connect(plainsocketimpl.java:188) @ java.net.plainsocketimpl.connect(plainsocketimpl.java:461) @ java.net.socket.connect(socket.java:918) @ java.net.socket.connect(socket.java:844) @ com.sun.mail.util.socketfetcher.createsocket(socketfetcher.java:233) @ com.sun.mail.util.socketfetcher.getsocket(socketfetcher.java:189) @ com.sun.mail.smtp.smtptransport.openserver(smtptransport.java:1359) ... 10 more caused by: android.system.errnoexception: isconnected failed: enetunreach (network unreachable) @ libcore.io.iobridge.isconnected(iobridge.java:252) ... 19 more
from logs:
java.net.connectexception: failed connect smtp.gmail.com/2a00:1450:4013:c01::6d (port 465) after 90000ms: isconnected failed: enetunreach (network unreachable)
network unreachable. code looks okay, therefore issue must network. please check connectivity. possible causes be:
- very slow/ bad network. try changing network.
- internet permission not available in manifest (this shouldn't case described problem). add permission.
for future, can add network-check before sending network requests. thread has answers checking network connectivity: how check internet access on android? inetaddress never times out
Comments
Post a Comment