eclipse - java.lang.RuntimeException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465 -
hello people of stackoverflow!
i've been trying hands on javamail api
// recipient's email id needs mentioned. string = "toaddrs@gmail.com";//change accordingly // sender's email id needs mentioned string = "fromaddrs@gmail.com";//change accordingly final string email = "emailaddrs@gmail.com";//change accordingly final string password = "xxxxxxxxx";//change accordingly // assuming sending email through relay.jangosmtp.net string host = "smtp.gmail.com"; properties props = new properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", host); props.put("mail.smtp.port", "465"); // session object. session session = session.getinstance(props, new javax.mail.authenticator() { protected passwordauthentication getpasswordauthentication() { return new passwordauthentication(email, password); } }); try { // create default mimemessage object. message message = new mimemessage(session); // set from: header field of header. message.setfrom(new internetaddress(from)); // set to: header field of header. message.setrecipients(message.recipienttype.to, internetaddress.parse(to)); // set subject: header field message.setsubject("testing subject"); // set actual message message.settext("hello, sample check send " + "email using javamailapi "); // send message transport.send(message); system.out.println("sent message successfully...."); } catch (messagingexception e) { throw new runtimeexception(e); }
the programs seems have no error, after executing i'm getting:
java.lang.runtimeexception: javax.mail.messagingexception: not connect smtp host: smtp.gmail.com, port: 465; nested exception is: java.net.connectexception: connection timed out: connect
can please me out on this??? << -> yes, i've configured gmail access less secured apps' option.... >>
thnks in advance!!
your firewall or proxy or anti-virus program preventing direct connections.
the javamail faq has tips connecting through proxy, , debugging tips determine why can't connect.
Comments
Post a Comment