java - Android Sending mail to gmail using smtp -


session session = null; progressdialog pdialog = null; context context = null; edittext reciep, sub, msg; string rec, subject, textmessage;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.b9);      context = this;      button login = (button) findviewbyid(r.id.btn_submit);     reciep = (edittext) findviewbyid(r.id.et_to);     sub = (edittext) findviewbyid(r.id.et_sub);     msg = (edittext) findviewbyid(r.id.et_text);      login.setonclicklistener(this); }  @override public void onclick(view v) {     rec = reciep.gettext().tostring();     subject = sub.gettext().tostring();     textmessage = msg.gettext().tostring();     properties props = new properties();     props.put("mail.smtp.host", "smtp.gmail.com");     props.put("mail.smtp.socketfactory.port", "587");     props.put("mail.smtp.socketfactory.class", "javax.net.ssl.sslsocketfactory");     props.put("mail.smtp.auth", "true");     props.put("mail.smtp.port", "587");      session = session.getdefaultinstance(props, new authenticator() {         protected passwordauthentication getpasswordauthentication() {             return new passwordauthentication("xyz@gmail.com", "xyz123");         }     });      pdialog = progressdialog.show(context, "", "sending mail...", true);      retrievefeedtask task = new retrievefeedtask();     task.execute();   } 

retrievefeedtask

  class retrievefeedtask extends asynctask<string, void, string> {      @override     protected string doinbackground(string... params) {          try{             message message = new mimemessage(session);             message.setfrom(new internetaddress("xyz@gmail.com"));             message.setrecipients(message.recipienttype.to, internetaddress.                     parse(rec));             message.setsubject(subject);             message.setcontent(textmessage, "text/html; charset=utf-8");             transport.send(message);         } catch(messagingexception e) {             e.printstacktrace();         } catch(exception e) {             e.printstacktrace();         }         return null;     }      @override     protected void onpostexecute(string result) {         pdialog.dismiss();         reciep.settext("");         msg.settext("");         sub.settext("");         toast.maketext(getapplicationcontext(), "message sent",        toast.length_long).show();     }  } } 

and getting following error couldn't able receive mail in inbox

error:

            javax.mail.messagingexception: not connect smtp host:         smtp.gmail.com, port: 587;              nested exception is:              avax.net.ssl.sslhandshakeexception: j        avax.net.ssl.sslprotocolexception: ssl     handshake aborted: ssl=0x755e6040:    failure in ssl library, protocol error                                                                                                   @ javax.mail.service.connect(service.java:310)                @ javax.mail.service.connect(service.java:169)                @ javax.mail.service.connect(service.java:118)                @ javax.mail.transport.send0(transport.java:188)                @ javax.mail.transport.send(transport.java:118)                  @ 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:841)                caused by: javax.net.ssl.sslhandshakeexception:       javax.net.ssl.sslprotocolexception: ssl handshake aborted: ssl=0x755e6040:     failure in ssl library, protocol error                error:140770fc:ssl routines:ssl23_get_server_hello:unknown     protocol   (external/openssl/ssl/s23_clnt.c:769 0x72fb0d74:0x00000000)             @  mpl.getinputstream(opensslsocketimpl.java:633) ﹕                       getselectedtext on inactive inputconnection                    getselectedtext on inactive inputconnection                    getselectedtext on inactive inputconnection                    getselectedtext on inactive inputconnection                     getselectedtext on inactive inputconnection                    getselectedtext on inactive inputconnection                    getselectedtext on inactive inputconnection                    getselectedtext on inactive inputconnection   getselectedtext on inactive inputconnection  gettextbeforecursor on inactive inputconnection 

if you're using ssl, correct port 465. 587 tls

https://support.google.com/mail/answer/13287?hl=en

if that's not problem, try following tutorial

http://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -