infisical icon indicating copy to clipboard operation
infisical copied to clipboard

Email isn't send using https self-hosted

Open levx-me opened this issue 1 year ago • 6 comments

Describe the bug

Email isn't send using https self-hosted

To Reproduce

Steps to reproduce the behavior:

  1. Go to 'Account Control'
  2. Click on 'Add Member'
  3. Type in email address
  4. See error
B86C4EE42E7F0000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:354:

Expected behavior

An email should be sent

Screenshots

Screenshot 2024-03-28 at 4 49 32 AM

Platform you are having the issue on:

Fedora 39

Additional context

I set up self hosted using docker-compose and I'm accessing it through https using nginx config like: TSL certificate was issued using certbot by letsencrypt and I'm bypassing request to 8001 which docker-compose is run at.

server {
        listen 443 ssl;
        server_name infisical.my.domain;

        ssl_certificate /etc/letsencrypt/live/infisical.my.domain/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/infisical.my.domain/privkey.pem;

        proxy_redirect      off;
        proxy_set_header    X-Real-IP $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    Host $http_host;

        location / {
            proxy_pass http://localhost:8001/;
            proxy_buffering off;
            proxy_buffer_size 16k;
            proxy_busy_buffers_size 24k;
            proxy_buffers 64 4k;
        }
    }

levx-me avatar Mar 27 '24 19:03 levx-me

Which email service are you using. https://infisical.com/docs/self-hosting/configuration/envars#email-service

akhilmhdh avatar Apr 01 '24 09:04 akhilmhdh

both gmail and resend doesn't work

levx-me avatar Apr 02 '24 12:04 levx-me

@levx-me are you able to try Sendgrid?

maidul98 avatar Apr 03 '24 23:04 maidul98

I faced the same issue when upgrading from infisical/infisical:v0.43.16 to infisical/infisical:v0.51.9-postgres self-hosted. Gmail SMTP stopped working.

based on infisical's SMTP docs: https://github.com/Infisical/infisical/blob/246e6c64d1e26f69a0ba8e006a329d8a2c11e919/docs/self-hosting/configuration/envars.mdx?plain=1#L212-L228


not work:

SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_SECURE="true"

works (port 465):

SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_SECURE="true"

works (secure false):

SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_SECURE="false"

Regarding to node mailer docs, which is used in Infisical (https://github.com/Infisical/infisical/blob/main/backend/package.json#L113)

https://www.nodemailer.com/smtp/

secure – if true the connection will use TLS when connecting to server. If false (the default) then TLS is used if server supports the STARTTLS extension. In most cases set this value to true if you are connecting to port 465. For port 587 or 25 keep it false

I think Infisical docs should be adjusted.

mtracz avatar Apr 08 '24 14:04 mtracz

Hmmm @mtracz good point. I think the default values should be adjusted according to this and also doc.

@levx-me Did port 465 resolved issue for you

akhilmhdh avatar May 14 '24 10:05 akhilmhdh

Hey, I'd like to follow up on this issue. We have Google Workspace accounts and cannot get SMTP to work in Infisical with our Google Workspace Gmail accounts. The only configuration that made it work halfway, is:

SMTP_HOST         = "smtp.gmail.com"
SMTP_PORT         = 465
SMTP_IGNORE_TLS   = "true"
SMTP_REQUIRE_TLS  = "false"
SMTP_USERNAME.    = "[email protected]"
SMTP_FROM_ADDRESS = "[email protected]"

At startup, I see

Testing smtp connection SMTP successfully connected

in the logs but as soon as I try to send an Email via Infisical, I receive the following error:

{"level":50,"time":1725099572402,"pid":1,"hostname":"infisical","reqId":"req-a","severity":"ERROR","err":{"type":"Error","message":"Mail command failed: 530-5.7.0 Must issue a STARTTLS command first. For more information, go to\n530-5.7.0 https://support.google.com/a/answer/3221692 and review RFC 3207\n530 5.7.0 specifications. a640c23a62f3a-a89891db022sm313303766b.146 - gsmtp","stack":"Error: Mail command failed: 530-5.7.0 Must issue a STARTTLS command first. For more information, go to\n530-5.7.0 https://support.google.com/a/answer/3221692 and review RFC 3207\n530 5.7.0 specifications. a640c23a62f3a-a89891db022sm313303766b.146 - gsmtp\n at SMTPConnection._formatError (/backend/node_modules/nodemailer/lib/smtp-connection/index.js:790:19)\n at SMTPConnection._actionMAIL (/backend/node_modules/nodemailer/lib/smtp-connection/index.js:1594:34)\n at SMTPConnection. (/backend/node_modules/nodemailer/lib/smtp-connection/index.js:1063:18)\n at SMTPConnection._processResponse (/backend/node_modules/nodemailer/lib/smtp-connection/index.js:969:20)\n at SMTPConnection._onData (/backend/node_modules/nodemailer/lib/smtp-connection/index.js:755:14)\n at SMTPConnection._onSocketData (/backend/node_modules/nodemailer/lib/smtp-connection/index.js:193:44)\n at Socket.emit (node:events:519:28)\n at Socket.emit (node:domain:488:12)\n at addChunk (node:internal/streams/readable:559:12)\n at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)","code":"EENVELOPE","response":"530-5.7.0 Must issue a STARTTLS command first. For more information, go to\n530-5.7.0 https://support.google.com/a/answer/3221692 and review RFC 3207\n530 5.7.0 specifications. a640c23a62f3a-a89891db022sm313303766b.146 - gsmtp","responseCode":530,"command":"MAIL FROM"},"msg":"Mail command failed: 530-5.7.0 Must issue a STARTTLS command first. For more information, go to\n530-5.7.0 https://support.google.com/a/answer/3221692 and review RFC 3207\n530 5.7.0 specifications. a640c23a62f3a-a89891db022sm313303766b.146 - gsmtp"}


EDIT1: I wasn't able to make it work with SMTP Relay either.

From https://support.google.com/accounts/answer/6010255?sjid=12320025837015455091-EU:

Less secure apps & your Google Account

Less secure apps & your Google Account Starting on September 30, 2024, less secure apps, third-party apps, or devices that have you sign in with only your username and password will no longer be supported for Google Workspace accounts. For exact dates, visit Google Workspace Updates. To continue to use a specific app with your Google Account, you’ll need to use a more secure type of access that doesn’t share password data. Learn how to use Sign in with Google.

If an app or site doesn’t meet our security standards, Google might block anyone who’s trying to sign in to your account from it. Less secure apps can make it easier for hackers to get in to your account, so blocking sign-ins from these apps helps keep your account safe.

Use more secure apps If an app uses less secure sign-in technology, you might not be able to use it with your Google Account.

Apps that use only your username or password will create errors if they try to access your Google Account. These errors can appear as:

“Invalid username” “Invalid password” “Unable to log in” You can sign in to your Google Account from any third-party app that has the "Sign in with Google" option. In some cases you may need to remove your Google Account and then add it again on your device.


Edit2: Maybe it is sufficient to simply request the appropriate Gmail scope https://developers.google.com/identity/protocols/oauth2/scopes when enabling SMTP. I envision the following scenario:

  1. We have an admin user in our organization with [email protected] alias.
  2. My Google Workspace admin user becomes the infisical admin user (and I attach Google OIDC in a second step).
  3. If you plan to not implement a UI to configure SMTP in the /admin route, preemptively request the Gmail scope in step 2. (or maybe based on some ENV var?)

What do you think?


EDIT3: Found a configuration through SMTP Relay that works. This is NOT A SOLUTION imho though. I'd rather see something close to my thoughts outlined in EDIT2 I guess.

For the SMTP Relay configuration, align with https://support.google.com/a/answer/2956491?hl=en

Allowed senders             - Only addresses in my domains
Require SMTP Authentication - Yes
Require TLS encryption      - No

with an example ENV var configuration for Infisical:

SMTP_HOST         = "smtp-replay.gmail.com"
SMTP_PORT         = 587
SMTP_USERNAME     = "[email protected]"
SMTP_PASSWORD     = "unsafe-app-password"
SMTP_FROM_ADDRESS = "[email protected]"
SMTP_FROM_NAME    = "Sadge Infisical SSO SAML is an EE Feature"

tafaust avatar Aug 31 '24 10:08 tafaust