1 (edited by admin@dpl.net.in 2015-05-02 15:39:39)

Topic: Android Email client/Mail sending through JAVA issue

==== Required information ====
- iRedMail version: 0.9.0
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx):Apache2
- Linux/BSD distribution name and version: Ubuntu 14.04
- Related log if you're reporting an issue:
====

We are using the  Iredmail over web access but we are facing issues while configuring the standard Android client for our mail server.

We are entering the static IP/Domain name for both pop3 and SMTP
Security Type - We have tried all possible combinations (STARTTLS,SSL/TLS)

We are getting an error like this-" Could not open connection to the server"

Further, while sending any mail grammatically through Java mail API, we are getting the following error message:

Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Could not connect to SMTP host: thedpl.in, port: 587;
  nested exception is:
    java.net.ConnectException: Connection refused: connect
    at utility.SendMailAttachmentDPL.main(SendMailAttachmentDPL.java:91)
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: thedpl.in, port: 587;
  nested exception is:
    java.net.ConnectException: Connection refused: connect
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
    at javax.mail.Service.connect(Service.java:317)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:125)
    at javax.mail.Transport.send0(Transport.java:194)
    at javax.mail.Transport.send(Transport.java:124)
    at utility.SendMailAttachmentDPL.main(SendMailAttachmentDPL.java:86)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:288)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:231)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
    ... 7 more

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: Android Email client/Mail sending through JAVA issue

admin@dpl.net.in wrote:

==== Required information ====
- iRedMail version: 0.9.0
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx):Apache2
- Linux/BSD distribution name and version: Ubuntu 14.04
- Related log if you're reporting an issue:
====

We are using the  Iredmail over web access but we are facing issues while configuring the standard Android client for our mail server.

We are entering the static IP/Domain name for both pop3 and SMTP
Security Type - We have tried all possible combinations (STARTTLS,SSL/TLS)

We are getting an error like this-" Could not open connection to the server"

Further, while sending any mail grammatically through Java mail API, we are getting the following error message:

Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Could not connect to SMTP host: thedpl.in, port: 587;
  nested exception is:
    java.net.ConnectException: Connection refused: connect
    at utility.SendMailAttachmentDPL.main(SendMailAttachmentDPL.java:91)
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: thedpl.in, port: 587;
  nested exception is:
    java.net.ConnectException: Connection refused: connect
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
    at javax.mail.Service.connect(Service.java:317)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:125)
    at javax.mail.Transport.send0(Transport.java:194)
    at javax.mail.Transport.send(Transport.java:124)
    at utility.SendMailAttachmentDPL.main(SendMailAttachmentDPL.java:86)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:288)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:231)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
    ... 7 more


I guess I am doing wrong in putting the pop3 and smtp URL.....

3

Re: Android Email client/Mail sending through JAVA issue

Pop3 (SSL) port 995
SMTP (TLS) port 587

the ports and SSL or TLS are very important.

4 (edited by admin@dpl.net.in 2015-05-02 19:28:21)

Re: Android Email client/Mail sending through JAVA issue

There are following options available in Android 4.4 email client

1. SSL/TLS
2. SSl/TLS(Accept all certificates)
3. STARTTLS
4. STARTTLS(Accept all certificates)

I have selected the 1st option and given the port number as mentioned by you but still I am receiving the same error- "Could not open connection to the server".

Tested the same configuration in MS Outlook also, fails there too.

5

Re: Android Email client/Mail sending through JAVA issue

I guess your client IP address was blocked in iptables, i suggest disable fail2ban service and restart iptables to flush firewall rules first, then try to configure mail clients again.

Recommended setup is:

*) IMAP: port 143 over TLS
*) POP3: port 110 over TLS
*) SMTP: port 587 over TLS

6

Re: Android Email client/Mail sending through JAVA issue

ZhangHuangbin wrote:

I guess your client IP address was blocked in iptables, i suggest disable fail2ban service and restart iptables to flush firewall rules first, then try to configure mail clients again.

Recommended setup is:

*) IMAP: port 143 over TLS
*) POP3: port 110 over TLS
*) SMTP: port 587 over TLS

Now the error has changed to "can not safely connect to the server".

7

Re: Android Email client/Mail sending through JAVA issue

You should be using (Accept all certificates) by the way,
Android /Java only marks the Certificate as valid if it is very high trust or manually specified in the Mail Application

8

Re: Android Email client/Mail sending through JAVA issue

I was doing it anyway. No luck. Same error.

I like to let you know that we have not installed any SSL certificate in our mail server,  as a result we are getting an error message while accessing the mail through roundcube that tge connection is not secured. After we accept to proceed we get the login page. Will installing a SSL certificate solve the problem?

But Android app for roundcube works smoothly.

9

Re: Android Email client/Mail sending through JAVA issue

admin@dpl.net.in wrote:

I like to let you know that we have not installed any SSL certificate in our mail server

iRedMail installs a self-signed certificate by default, did you remove it?

Show us below info:

*) Command output: netstat -ntlp
*) Screenshot of setup on your phone.

10 (edited by admin@dpl.net.in 2015-05-04 14:50:08)

Re: Android Email client/Mail sending through JAVA issue

ZhangHuangbin wrote:
admin@dpl.net.in wrote:

I like to let you know that we have not installed any SSL certificate in our mail server

iRedMail installs a self-signed certificate by default, did you remove it?

Show us below info:

*) Command output: netstat -ntlp
*) Screenshot of setup on your phone.

No, I have not deleted any certificate. iRedMail.crt is located at /etc/ssl/certs/


Output of netstat -ntlp:-

root@mail:~# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN      1060/dnsmasq   
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      23677/cupsd     
tcp        0      0 0.0.0.0:24              0.0.0.0:*               LISTEN      962/dovecot     
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      2622/master     
tcp        0      0 0.0.0.0:4190            0.0.0.0:*               LISTEN      962/dovecot     
tcp        0      0 127.0.0.1:7777          0.0.0.0:*               LISTEN      23708/python   
tcp        0      0 0.0.0.0:993             0.0.0.0:*               LISTEN      962/dovecot     
tcp        0      0 0.0.0.0:995             0.0.0.0:*               LISTEN      962/dovecot     
tcp        0      0 127.0.0.1:10024         0.0.0.0:*               LISTEN      1178/amavisd-new (m
tcp        0      0 127.0.0.1:10025         0.0.0.0:*               LISTEN      2622/master     
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1047/mysqld     
tcp        0      0 0.0.0.0:587             0.0.0.0:*               LISTEN      2622/master     
tcp        0      0 127.0.0.1:9998          0.0.0.0:*               LISTEN      1178/amavisd-new (m
tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN      962/dovecot     
tcp        0      0 127.0.0.1:10031         0.0.0.0:*               LISTEN      2643/perl       
tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN      962/dovecot     
tcp6       0      0 ::1:631                 :::*                    LISTEN      23677/cupsd     
tcp6       0      0 :::24                   :::*                    LISTEN      962/dovecot     
tcp6       0      0 :::25                   :::*                    LISTEN      2622/master     
tcp6       0      0 :::443                  :::*                    LISTEN      2716/apache2   
tcp6       0      0 :::4190                 :::*                    LISTEN      962/dovecot     
tcp6       0      0 :::993                  :::*                    LISTEN      962/dovecot     
tcp6       0      0 :::995                  :::*                    LISTEN      962/dovecot     
tcp6       0      0 :::587                  :::*                    LISTEN      2622/master     
tcp6       0      0 :::110                  :::*                    LISTEN      962/dovecot     
tcp6       0      0 :::143                  :::*                    LISTEN      962/dovecot     
tcp6       0      0 :::80                   :::*                    LISTEN      2716/apache2


The screen shot of set up also attached.

Post's attachments

Screenshot_2015-05-04-10-13-09.png 61.01 kb, 1 downloads since 2015-05-04 

Screenshot_2015-05-04-10-13-30.png 82.26 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

11

Re: Android Email client/Mail sending through JAVA issue

Any chance you use cloudflare or similar?

12

Re: Android Email client/Mail sending through JAVA issue

7t3chguy wrote:

Any chance you use cloudflare or similar?

No, We have not used any such services.

13

Re: Android Email client/Mail sending through JAVA issue

The problem has been rectified.  The issue was related to certificate mismatch between the mail server and JRE from which the JavaMail API is being used. Java considers security as prime factor hence does not allow any self signed SSL to be used for SMTP. Hence the self signed certificate has to be imported to local JRE(from which the user will be sending the mails) through keytool utility.

Now regarding android client.... There are some mobile phone manufactures like XIAOMI who actually customize a lot on the stock Android email client. As we all know Apps on Android are written in Java, hence security is very very crucial and the server SSL certficate will also has to imported to the individual handset in case the mail server is using self signed SSL.

I am sure this information is going to save a lot of software professional from wasting a lot of time.

14

Re: Android Email client/Mail sending through JAVA issue

It's recommended to buy a ssl certificate to avoid this issue.