E-mail Sending Error using Hotmail as Commonsmail Java

Asked

Viewed 299 times

1

I am having trouble sending email using Outlook by returning the following error.

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

I tried the door 587 and with the smtp smtp-mail.outlook.com, but to no avail.

Follow the code I use for sending.

  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();

1 answer

2


I usually use it 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 believe it is just problem on the host, try to change the

smtp-mail.outlook.com

for

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 the 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);
        }
    }
}
  • Good morning buddy, can you give me a more complete example of this situation?

  • Good morning, I edited the reply by adding an example of sending an email using javamail

Browser other questions tagged

You are not signed in. Login or sign up in order to post.