java - Why cant send mail through smtp server? -
i try send mail hotmail yahoo/gmail using code below smtp.live.com or smtp-mail.outlook.com keep getting error :
string = sendto.gettext(); string = username; java.security.security.addprovider(new com.sun.net.ssl.internal.ssl.provider()); properties properties = system.getproperties(); properties.put("mail.smtp.ssl.enable","true"); properties.put("mail.smtp.host", "smtp.live.com"); // try smtp-mail.outlook.com cant properties.put("mail.smtp.port", 465); properties.put("mail.smtp.auth", "true"); authenticator authenticator = new authenticator() { protected passwordauthentication getpasswordauthentication() { return new passwordauthentication(username,passwd); }}; session session = session.getinstance(properties,authenticator); //default session if(attachment.gettext().isempty()){ try{ mimemessage message = new mimemessage(session); //email message message.setfrom(new internetaddress(from)); //setting header fields message.addrecipient(message.recipienttype.to, new internetaddress(to)); message.setsubject(subjectfield.gettext()); //subject line //mail body message.settext(textarea.gettext()); transport transport = session.gettransport("smtp"); transport.connect(host, from, to); //host = smtp.live.com from=abc@hotmail.com to=def@gmail.com transport.sendmessage(message, message.getallrecipients()); transport.close(); system.out.println("sent message successfully....");
error:
javax.mail.messagingexception: not connect smtp host: smtp.live.com, port: 465; nested exception is: java.net.connectexception: connection timed out: connect @ com.sun.mail.smtp.smtptransport.openserver(smtptransport.java:1934) @ com.sun.mail.smtp.smtptransport.protocolconnect(smtptransport.java:638) @ javax.mail.service.connect(service.java:295) @ javax.mail.service.connect(service.java:176)
neither host smtp.live.com
nor host smtp-mail.outlook.com
appears accept connections on port 465.
you should using port 587 instead.