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

SSL for e-mail #13

Closed
PandemiK911 opened this issue Apr 21, 2021 · 7 comments
Closed

SSL for e-mail #13

PandemiK911 opened this issue Apr 21, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@PandemiK911
Copy link

Hello,
Still on my deep testing ;-)

May we add an option to use SSL in addition to STARTTLS for e-mail ? Yes, we better use full-TLS than STARTTLS to get an encrypted dialog from the start.

In internal/common/email.go :
Use the TLS variable with :

This will retain compatibility with already-configured instances. In documentation, switch to "none/starttls/ssl" pragma to be able to disable the true/false option later as it's an incompatible change.

Thanks !

@h44z h44z added the enhancement New feature or request label Apr 22, 2021
@PandemiK911
Copy link
Author

Thanks for this. I can't confirm it's working : I'm getting the error "wrong host name".

This is probably not related to your code. The only reference to this error I can find : jordan-wright/email#103

It's relevant as our SMTP server only accept AUTH login method which is not supported by the email library.

I'll try to find another SMTP server to test the feature.

@PandemiK911
Copy link
Author

PandemiK911 commented Apr 22, 2021

Just tried with a StartTLS and TLS-capable server. I only changed EMAIL_PORT (587/465) and EMAIL_ENCRYPTION (starttls/tls).
E-mail was sent successfully with starttls and failed with tls (same error "wrong host name").

I've not been able to find where the error is (go-email, net/smtp ?).

All I can say is that go-email use smtp.Dial(addr) in SendWithStartTLS function and tls.Dial("tcp", addr, t) in SendWithTLS. No idea if this could have an impact ...

@h44z
Copy link
Owner

h44z commented Apr 22, 2021

I tried it with the following settings and it worked:

  • EMAIL_HOST=10.10.1.10
  • EMAIL_PORT=465
  • EMAIL_CERT_VALIDATION=false
  • EMAIL_ENCRYPTION=tls

Can you test out if it works if you connect via IP address?

@PandemiK911
Copy link
Author

Hello,
I should miss something. I tired a lot of different settings on 2 different server. I even created a TLS-enabled server and tried it with openssl s_client (with AUTH LOGIN), always the same message, despite using the IP or FQDN.

My settings are :
- MAIL_FROM=WireGuard VPN noreply@company.com
- EMAIL_HOST=smtp.domain.com
- EMAIL_PORT=466
- EMAIL_ENCRYPTION=tls
- EMAIL_USERNAME=sendmail@domain.com
- EMAIL_PASSWORD=mypassword
- EMAIL_CERT_VALIDATION=true

Port 466 is due to my last test with a nginx reverse proxy for SMTP.

As last resort, I ran a test container (praqma/network-multitool) with host networking to see if I can also connect with openssl s_client and it worked.

Really dunno what else I can try.

@h44z
Copy link
Owner

h44z commented Apr 26, 2021

Hi @Azylog ,

what I found out now is that this error is triggered by the mail server if the hostname that is specified in the PlainAuth differs from the mail server hostname.

See https://groups.google.com/g/golang-nuts/c/5j1r43_Q4B8 or prometheus/alertmanager#1174.

I just dont know why the encryption method makes a difference here... Is your mail server configured to respond the same hostname on all ports/protocols?

@PandemiK911
Copy link
Author

You sent me on the right direction.
I can find the error here https://golang.org/src/net/smtp/auth.go at line 72.

I don't really understand clearly where the compared strings come from (server.Name != a.host).
Just to be sure : all certificates of my test servers are valid (not self signed) Let's Encrypt certs and aligned with FQDN. This should not be an issue. I also tried with and without the fullchain (aka intermediate certs with server cert), nothing more.

Could it be due to the fact you're creating the Auth structure only with 'hostname' and establishing connection to 'hostname:port' ?

h44z added a commit that referenced this issue Apr 29, 2021
@h44z
Copy link
Owner

h44z commented May 4, 2021

Should be fixed with the new email library.

@h44z h44z closed this as completed May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants