1

I have small java program i wrote to send email. I am running this program from eclipse.

public static void sendMail(){      
    Properties prop = new Properties();     
    prop.setProperty("mail.host", "****.com");      
    prop.setProperty("mail.smtp.port", "25");
    prop.setProperty("mail.smtp.auth", "false");        
    Session sess = Session.getDefaultInstance(prop);        
    Message msg = new MimeMessage(sess);
        try {
            msg.setSubject("From me");
            msg.setText("Hello");
            msg.setFrom(new InternetAddress("****@***com","Me"));
            msg.setRecipient(Message.RecipientType.TO, new InternetAddress("****@****.com"));
            Transport.send(msg);
        } catch (MessagingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    System.out.println("mail Sent");
}

It throes following error

com.sun.mail.util.MailConnectException: Couldn't connect to host, port:      *****.com, 25; timeout -1;
 nested exception is:
java.net.SocketException: Permission denied: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2054)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697)
at javax.mail.Service.connect(Service.java:345)
at javax.mail.Service.connect(Service.java:226)
at javax.mail.Service.connect(Service.java:175)
at javax.mail.Transport.send0(Transport.java:253)
at javax.mail.Transport.send(Transport.java:124)
at json.mail.sendMail(mail.java:33)

Following things i have tried so far but none of it worked.
1. Disabled Firewall.
2. added following line to eclipse.ini
-Djava.net.preferIPv4Stack=true

None of it actually worked. Does anyone have any idea?

Nomad
  • 1,019
  • 4
  • 16
  • 30

0 Answers0