Should you get an error in Roundcube "SMTP Error (-1): Connection to server failed" when trying to send emails check our case as yours might be the same. Here we will suggest a solution which worked for us.
In roundcube you might see errors of the following kind:
[20-Feb-2018 07:13:42 UTC] ERROR: Conexión rehusada (111) [20-Feb-2018 07:13:42 UTC] ERROR: Failed to connect socket: Conexión rehusada () [20-Feb-2018 07:13:42 +0000]: <e7lt1hgd> SMTP Error: Connection failed: Failed to connect socket: Conexión rehusada in /var/www/html/roundcubemail-1.3.4/program/lib/Roundcube/rcube.php on line 1667 (POST /roundcube/?_task=mail&_unlock=loading1519110819239&_lang=undefined&_framed=1&_action=send)
If you have CSF/LFD installed you might have SMTP_BLOCK enabled in it. So let's check:
grep ^SMTP_BLOCK /etc/csf/csf.conf
If you see SMTP_BLOCK = "1" then it mean that outgoing connections to 25, 465, 587 are forbidden. Unfortunately it blocks connections from Roundcube too.
It can be fixed without disabling SMTP block, the following way. You need to add user webapps into SMTP_ALLOWUSER and restart csf/lfd. Check:
# grep ^SMTP_ /etc/csf/csf.conf
SMTP_BLOCK = "1"
SMTP_ALLOWLOCAL = "0"
SMTP_REDIRECT = "0"
SMTP_PORTS = "25,465,587"
SMTP_ALLOWUSER = "webapps"
SMTP_ALLOWGROUP = "mail,mailman"
Now RoundCube should have permission to connect to SMTP server.
If you still face issues, please feel free to contact us for an assistance.