2

JavaMail API to iMail -- java.net.SocketException: Permission denied: connect

I did the changes as suggested in the above link I still face this same issue I was using jdk1.8 but tried with JDK 6 and added -Djava.net.preferIPv4Stack=true to the VM options too

    Properties props = System.getProperties();
    props.put("mail.host",smtpHostServer );
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "25");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smptp.ssl.enable", true);
    props.put("mail.smtp.ssl.trust", smtpHostServer);
    props.put("mail.debug", "true");
    props.put("mail.smtp.socketFactory.port", "25");
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.socketFactory.fallback", "false");


    Session session = Session.getInstance(props, null);
    session.setDebug(true);

    EmailUtil.sendEmail(session, emailID,"SimpleEmail Testing Subject", "SimpleEmail Testing Body");

I get the below log , not sure if its got to do with account rights since im using a corporate account MS exchange server e.g: abc@xyz.com

`DEBUG: setDebug: JavaMail version 1.5.5
Message is ready
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "xxxxx.xxxxx.com", port 25, isSSL false
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: xxxx.xxxxxx.com, 25; timeout -1;
  nested exception is:
    java.net.SocketException: Permission denied: connect
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2100)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:699)
    at javax.mail.Service.connect(Service.java:366)
    at javax.mail.Service.connect(Service.java:246)
    at javax.mail.Service.connect(Service.java:267)
    at com.test.spring.mail.EmailUtil.sendEmail(EmailUtil.java:71)
    at com.test.spring.mail.MailServiceTest.main(MailServiceTest.java:44)
Caused by: java.net.SocketException: Permission denied: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:529)
    at java.net.Socket.connect(Socket.java:478)
    at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:331)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:217)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2066)
    ... 6 more`
Community
  • 1
  • 1
LETITIA DSOUZA
  • 101
  • 2
  • 3
  • Many modern servers don't allow connection via port 25 and require TLS or some other kind of encryption. Can you telnet to your host using port 25 and type "HELO"? – user3486184 Jul 28 '16 at 22:12
  • This will be an outbound firewall rule at the client end. Remove it. Remove all outbound firewall rules. They contribute nothing to security. – user207421 Jul 28 '16 at 23:59
  • SMTP connection failed and got a new server & port for the e-mail transfer Thank you – LETITIA DSOUZA Jul 29 '16 at 23:49

0 Answers0