Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMTP connection fails #237

Open
Has-X opened this issue Dec 17, 2023 · 7 comments
Open

SMTP connection fails #237

Has-X opened this issue Dec 17, 2023 · 7 comments
Labels
needs-feedback Waiting for feedback from reporter

Comments

@Has-X
Copy link

Has-X commented Dec 17, 2023

I cannot send an email trough smtp no matter what I do, I tested with other mail clients and it works, expect for Roundcube docker,

My docker log:

errors: <9ea8998e> PHP Error: STARTTLS failed (POST /?_task=mail&_unlock=loading1702834244555&_framed=1&_lang=en&_action=send)
errors: <9ea8998e> PHP Error: Invalid response code received from server (POST /?_task=mail&_unlock=loading1702834244555&_framed=1&_lang=en&_action=send)
errors: <9ea8998e> SMTP Error: STARTTLS failed: 2.0.0 Ready to start TLS (Code: 220) in /var/www/html/program/lib/Roundcube/rcube.php on line 1794 (POST /?_task=mail&_unlock=loading1702834244555&_framed=1&_lang=en&_action=send)

My postfix log:

Dec 17 17:30:49 mail.rokal.es postfix/smtpd[9891]: connect from ip51.ip-87-98-146.eu[87.98.146.51]
Dec 17 17:30:50 mail.rokal.es postfix/smtpd[9891]: lost connection after STARTTLS from ip51.ip-87-98-146.eu[87.98.146.51]
Dec 17 17:30:50 mail.rokal.es postfix/smtpd[9891]: disconnect from ip51.ip-87-98-146.eu[87.98.146.51]

@fager
Copy link

fager commented Jan 17, 2024

I have the same problem with my installation.

Connections (imap and smtp) without tls work but as soon as I activate tls I get these error messages.

My Postfix and Dovecot have certificates from Let's Encrypt. Both certificate chains don't seem to be present in the Docker image.

Test:

docker exec -it <container-name> bash
curl -v https://<FQDN-of-some-Lets-Encrypt-Website>/
...
curl: (60) SSL certificate problem: unable to get local issuer certificate
...

I created my own container image in which I added the Let's Encrypt certificate chain to /usr/local/share/ca-certificates/ and updated the CA files with "RUN update-ca-certificates".

Afterwards I can successfully validate the server certificate using curl.

PHP can now apparently validate the certificate with the PHP default config.

Test:

php -r "print(file_get_contents('https://<FQDN-of-some-Lets-Encrypt-Website>'));"

But Roundcube still cannot validate the Let's Encrypt certificate during imap or smtp connections with tls.

I then converted my configuration to the advanced configuration and set the options "smtp_conn_options" and "imap_conn_options" to point to /etc/ssl/certs/ca-certificates.crt.

$config['imap_conn_options'] = [
    'ssl' => [
        'verify_peer'  => true,
        'verify_depth' => 3,
        'cafile'       => '/etc/ssl/certs/ca-certificates.crt',
    ],
];
$config['smtp_conn_options'] = [
    'ssl' => [
        'verify_peer'  => true,
        'verify_depth' => 3,
        'cafile'       => '/etc/ssl/certs/ca-certificates.crt',
    ],
];

With this configuration, SMTP and IMAP are both TLS protected and working.

It would be nice to extend the Entrypoint script so that it updates the CA chain if, for example, a directory with additional CA certificates is mounted under /certs/. And an adapted *_conn_options configuration could be included in the container image, which points to the correct ca_file.

@pabzm
Copy link
Member

pabzm commented Nov 7, 2024

I cannot reproduce that. Can you specify a full example, including a hostname?

@pabzm pabzm added the needs-feedback Waiting for feedback from reporter label Nov 7, 2024
@urbaman
Copy link

urbaman commented Dec 26, 2024

Hi,

Actually not connecting to my mailserver (letsencrypt/selfsigned certs), ports 993 and 465 (ssl://mail.domain.com).

I think the certs are actually selfsigned, I would need to be able to set:

$config['imap_conn_options'] = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
];

$config['smtp_conn_options'] = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
];

from variables (like ssl_skip_verify or something of the kind)

@pabzm
Copy link
Member

pabzm commented Jan 2, 2025

What I couldn't reproduce is PHP not being able to validate letsencrypt certificates. Can someone else reproduce that?

To use self-signed certificates the shown configuration is required. I don't want to include that into the images because such a configuration shouldn't be used in a productive environment, I think.

@urbaman
Copy link

urbaman commented Jan 2, 2025

I actually solved: my mailserver, being multi-domain, did not use different certs for different domains, just used the principal sever domain for the smtp/imap certs. Once I pointed to the right domain, the domain validation worked out flawlessly.

@pabzm
Copy link
Member

pabzm commented Jan 2, 2025

@urbaman Nice!

@Has-X, @fager Do you still have this problem? Can you provide feedback if the problem exists with certs that are usually publicly trusted (like letsencrypt)?

@fager
Copy link

fager commented Jan 2, 2025

@pabzm

I have created the first step of a possible implementation as a pull request.

If you agree with the implementation, the PHP still needs to be made to use the correct file (/etc/ssl/certs/ca-certificates.crt). Since I'm not much of a PHP person anymore, maybe you could give me a tip on how you would like to have the configuration adjustment implemented best...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-feedback Waiting for feedback from reporter
Projects
None yet
Development

No branches or pull requests

4 participants