I try to send mail from hotmail to yahoo/gmail using code as below with smtp.live.com or smtp-mail.outlook.com but keep getting error :
String to = SendTo.getText();
String from = useame;
java.security.Security.addProvider(new com.sun.net.ssl.inteal.ssl.Provider());
Properties properties = System.getProperties();
properties.put("mail.smtp.ssl.enable","true");
properties.put("mail.smtp.host", "smtp.live.com"); // i try smtp-mail.outlook.com also cant
properties.put("mail.smtp.port", 465);
properties.put("mail.smtp.auth", "true");
Authenticator authenticator = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
retu new PasswordAuthentication(useame,passwd);
}};
Session session = Session.getInstance(properties,authenticator); //default session
if(attachment.getText().isEmpty()){
try{
MimeMessage message = new MimeMessage(session); //email message
message.setFrom(new InteetAddress(from)); //setting header fields
message.addRecipient(Message.RecipientType.TO, new InteetAddress(to));
message.setSubject(subjectField.getText()); //subject line
//mail body
message.setText(TextArea.getText());
Transport transport = session.getTransport("smtp");
transport.coect(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: Could not coect to SMTP host: smtp.live.com, port: 465;
nested exception is:
java.net.CoectException: Coection timed out: coect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
at com.sun.mail.smtp.SMTPTransport.protocolCoect(SMTPTransport.java:638)
at javax.mail.Service.coect(Service.java:295)
at javax.mail.Service.coect(Service.java:176)
