Error sending E-mail using Hotmail as CommonsMail Java

1

I'm having trouble sending email using Outlook, returning the following error.

Erro Sending the email to the following server failed: smtp.live.com:25

I have tried with port 587 and smtp smtp-mail.outlook.com , but with no success.

Follow the code I use for uploading.

  HtmlEmail email = new HtmlEmail();
    email.setSSLOnConnect(true);
    email.setHostName("smtp-mail.outlook.com");
    email.setSslSmtpPort(587);
    email.setAuthenticator(new DefaultAuthenticator("[email protected]", "12345678"));

    try {
        email.setFrom("[email protected]");

        email.setDebug(true);

        email.setSubject(tituloEmail);
        email.setHtmlMsg(conteudo);
        email.addTo(destinatario);


        email.send();
    
asked by anonymous 24.02.2017 / 14:41

1 answer

2

I usually use this way with java mail

        Properties propertie = new Properties();  
        propertie.put("mail.transport.protocol", "smtp");  
        propertie.put("mail.smtp.host", "smtp.live.com");  
        propertie.put("mail.smtp.socketFactory.port", "587");  
        propertie.put("mail.smtp.socketFactory.fallback", "false");  
        propertie.put("mail.smtp.starttls.enable", "true");  
        propertie.put("mail.smtp.auth", "true");  
        propertie.put("mail.smtp.port", "587");  
        session = Session.getDefaultInstance(propertie,  
                    new javax.mail.Authenticator() {  
                         protected PasswordAuthentication getPasswordAuthentication()   
                         {  
                               return new PasswordAuthentication("[email protected]", "suasenha");  
                         }  
                    }); 

I think it's just a problem on the host, try changing the

smtp-mail.outlook.com

by

smtp.live.com

.

HtmlEmail email = new HtmlEmail();
email.setHostName("smtp.live.com");
email.setSslSmtpPort(587);
email.setAuthenticator(new DefaultAuthenticator("[email protected]", "suasenha"));

Edited

Example using javaMail

public class SendMail {

    public static void main(String[]args) throws IOException {

        final String username = "[email protected]";
        final String password = "suasenha";

        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", "outlook.office365.com");
        props.put("mail.smtp.port", "587");

        Session session = Session.getInstance(props,
          new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
          });

        try {

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("seuemail@outlook"));
            message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("emaildestino@..."));
            message.setSubject("Testando");
            message.setText("Olá");

            Transport.send(message);
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
}
    
27.02.2017 / 16:12