title: Javamail - sending mail from localhost to external accounts
body: <p>Need to send email from localhost to external accounts like gmail and yahoo. Right now i have a program which can send and recieve mails from my local domain by local email server up and running eg (admin@ib-status.com &lt;-> devteam@ib-status.com). But problem is when i try to send from local domain to gmail or yahoo account i'm Unable to do it eg(admin@ib-status.com -> myaccount@gmail.com). Need help on this</p>
  
  <p>PS. I'm Using Hmailserver for emailserver</p>
  
  <pre><code>public class JMailer {
  
            private static String HOSTNAME = "localhost";
              private static String USERNAME = "admin";
              private static String PASSWORD = "Mylocaldomainpassword";
  
              public static void main(String[] args) {
              try {  
                  String to = "MygmailAccount@gmail.com";
                  String from = "admin@ib-status.com";               
                  Properties properties = System.getProperties();
  
                  properties.setProperty("mail.smtp.host",HOSTNAME);
                  Session session = Session.getInstance(properties, new Authenticator() {                
                      protected PasswordAuthentication getPasswordAuthentication() {
                          return new PasswordAuthentication(USERNAME, PASSWORD);
                      }
                  });
                      MimeMessage message = new MimeMessage(session);
                      message.setFrom(new InternetAddress(from));
                      message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
                      message.setSubject("My Subject!");
                      message.setText("Here Goes My Message");                    
                      Transport.send(message);
                      System.out.println("Message Sending Completed");
                  } catch (MessagingException mex) {
                      mex.printStackTrace();
                  }
              }
  }
  </code></pre>
  
  <p>and my error from Hmailserver log is below</p>
  
  <p>"SMTPC" 4508    0   "2014-06-13 15:18:01.022"   "TCP"   "SMTPDeliverer - Message 13 - Connection failed: Host name: 74.125.25.27, message: <strong>No connection could be made because the target machine actively refused it"</strong></p>
  
  <p>did i miss anything here?why remote machine's connection is refused ? and i dont want to use gmail's SMTP server to send message.all i need is i want my own smtp sever running to send and recieve</p>