title: after sending few emails Could not connect to SMTP host , nested exception is: java.net.ConnectException: Connection refused: connect
body: <p>I want to get all unread emails from server and send each message to another email. When I send each unread email (Using HostGator), after sending few mails (30-40) an error occurs as I mentioned. This is my sending method. What can i do? I checked with smtp port 25,465,587. but none of them worked. Same error appears. :/ if any one knows how to handle it please let me know. Thank you..</p>
  
  <p>email send method:-</p>
  
  <pre><code>public static void send(String sub,final String user, final String pass, String toMails) throws Exception {   
      Properties props = new Properties();
      props.put("mail.smtp.host", "gator.hostgator.com");
      props.put("mail.smtp.port", "25");
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.starttls.enable", "true");
  
      Session session = Session.getInstance(props, new javax.mail.Authenticator() {
          protected PasswordAuthentication getPasswordAuthentication() {
              return new PasswordAuthentication(user, pass);
          }
      });
      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(user));
      message.addRecipients(Message.RecipientType.TO, toMails);
  
      message.setSubject(sub);
      message.setText("-Body-");
  
      BodyPart messageBodyPart1 = new MimeBodyPart();
      messageBodyPart1.setText("-Body-");      
  
      Multipart multipart = new MimeMultipart();
      multipart.addBodyPart(messageBodyPart1);    
      message.setContent(multipart);  
      Transport.send(message);
  }
  </code></pre>
  
  <p>This is error message :-<a href="https://i.stack.imgur.com/N4nMQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N4nMQ.png" alt="enter image description here"></a></p>