rnwood / smtp4dev

smtp4dev - the fake smtp email server for development and testing
BSD 3-Clause "New" or "Revised" License
3.1k stars 346 forks source link

selfsigned certificate name mismatch on MacOS 12.0.1 with Docker and Mailkit #1222

Closed jf-gbg closed 1 year ago

jf-gbg commented 1 year ago

Using the automatically generated selfsigned certificate produces this error in MacOS:

"The host name did not match the name given in the server's SSL certificate".

Both the host name and the certificate have the name "localhost" and this can be seen when I check the certificate details whilst debugging. I have trusted the self signed certificate in my keychain but that did not help. I have also tried generating my own certificate and adding that to the below configuration variable:

ServerOptions__TlsCertificate=~/dev/cert.crt

However, that produces this error when I use docker compose up:

The SMTP server failed to start: Interop+Crypto+OpenSslCryptographicException: error:2006D080:BIO routines:BIO_new_file:no such file

The issue is only present on MacOS, I have tested on Windows and it works as expected without issue.

EDIT: Having had an evening to step away from this, I think the most likely cause of the problem is to do with the way mac deals with certificates, so not an SMTP4Dev issue. However, I would be interested to know how to correctly set the certificate from docker-compose.

jf-gbg commented 1 year ago

I haven't had time to fully investigate this myself with this app as I've had other work to focus on, however, I think the route issue with this might be with the hosts file on macos and it not seeing the localhost in the smtp4dev certificate as the same localhost because it's in Docker. It is possible to add docker to your hosts file using: host.docker.internal.