pglombardo / PasswordPusher

🔐 Securely share sensitive information with automatic expiration & deletion after a set number of views or duration. Track who, what and when with full audit logs.
https://docs.pwpush.com
Apache License 2.0
1.94k stars 341 forks source link

E-mail not sending on docker enviroment #1355

Open MkosterNet4it opened 1 year ago

MkosterNet4it commented 1 year ago

🐛 Bug Report

Mails not sending on custom docker enviroment, getting Error #500

🔬 How To Reproduce

Steps to reproduce the behavior:

  1. setup with docker image pglombardo/pwpush-postgres:release
  2. configure db connection and environment
  3. register new user -> no registration mail send
  4. test with forgot password -> no mail send

Code sample

  PWP__ENABLE_LOGINS: "true"
  PWP__MAIL__RAISE_DELIVERY_ERRORS: "true"
  PWP__MAIL__SMTP_ADDRESS: "smtp.office365.com"
  PWP__MAIL__SMTP_PORT: "587"
  PWP__MAIL__SMTP_USER_NAME: "_email_"
  PWP__MAIL__SMTP_PASSWORD: "_password_"
  PWP__MAIL__SMTP_AUTHENTICATION: "login"
  PWP__MAIL__SMTP_STARTTLS: "false"
  PWP__MAIL__SMTP_ENABLE_STARTTLS_AUTO: "false"
  PWP__MAIL__OPEN_TIMEOUT: "10"
  PWP__MAIL__READ_TIMEOUT: "10"
  PWP__HOST_DOMAIN: "_fqdn_"
  PWP__HOST_PROTOCOL: "https"

Environment

Where are you running/using Password Pusher?

If applicable, what version of Password Pusher?

Screenshots

image

📈 Expected behavior

E-mails being sent to the users, so that we can create the accounts for our company.

📎 Additional context

Rails.application.config.action_mailer.smtp_settings
{:address=>"smtp.office365.com",
 :port=>587,
 :user_name=>"_email_",
 :password=>"_password_",
 :authentication=>"login",
 :enable_starttls_auto=>true,
 :open_timeout=>10,
 :read_timeout=>10}
irb(main):020:1* Mail.deliver do
irb(main):021:1*   to 'email'
irb(main):022:1*   from 'email'
irb(main):023:1*   subject 'testing mail'
irb(main):024:1*   body 'testing mail'
irb(main):025:0> end
/usr/local/lib/ruby/3.2.0/socket.rb:1217:in `__connect_nonblock': Address not available - connect(2) for [::1]:25 (Errno::EADDRNOTAVAIL)

Hope anyone can help me figure this out

github-actions[bot] commented 1 year ago

Hello @MkosterNet4it, thanks for contributing to the Password Pusher community! We will respond as soon as possible.

pglombardo commented 1 year ago

Hi @MkosterNet4it a couple ideas:

  1. Office365 removed basic authentication I believe. Take a look at these issues for more information:
    • 982

    • 532

    • 265

  2. Did you also set the required PWP__MAIL__MAILER_SENDER? This has to be valid email format e.g. '"Password Pusher" <pglombardo@pwpush.com>'
  3. Try setting PWP__MAIL__SMTP_ENABLE_STARTTLS_AUTO=false - this has shown to fix the 500 in some cases (docs)
  4. And finally, if you could retrieve the stack trace from the container in /opt/PasswordPusher/logs that would show us exactly what the SMTP error is in the application

Re:

/usr/local/lib/ruby/3.2.0/socket.rb:1217:in `__connect_nonblock': Address not available - connect(2) for [::1]:25 (Errno::EADDRNOTAVAIL)

It's odd that it attempted to connect on port 25 here despite configuring 587...

Hopefully this will put us on the right path. Let me know.

MkosterNet4it commented 1 year ago

Hi @MkosterNet4it a couple ideas:

  1. Office365 removed basic authentication I believe. Take a look at these issues for more information:

  2. Did you also set the required PWP__MAIL__MAILER_SENDER? This has to be valid email format e.g. '"Password Pusher" <pglombardo@pwpush.com>'
  3. Try setting PWP__MAIL__SMTP_ENABLE_STARTTLS_AUTO=false - this has shown to fix the 500 in some cases (docs)
  4. And finally, if you could retrieve the stack trace from the container in /opt/PasswordPusher/logs that would show us exactly what the SMTP error is in the application

Re:

/usr/local/lib/ruby/3.2.0/socket.rb:1217:in `__connect_nonblock': Address not available - connect(2) for [::1]:25 (Errno::EADDRNOTAVAIL)

It's odd that it attempted to connect on port 25 here despite configuring 587...

Hopefully this will put us on the right path. Let me know.

Hey @pglombardo I just checked the error log and found this

[2023-08-15T06:56:14.581162 #199] FATAL -- : [e6b404e8-ff01-4f6a-864c-ca3195ca5b44]
[e6b404e8-ff01-4f6a-864c-ca3195ca5b44] Net::SMTPSyntaxError (504 5.7.4 Unrecognized authentication type [AM0PR10CA0090.EURPRD10.PROD.OUTLOOK.C):
[e6b404e8-ff01-4f6a-864c-ca3195ca5b44]
[e6b404e8-ff01-4f6a-864c-ca3195ca5b44] app/controllers/application_controller.rb:14:in `custom_set_locale_from_url'

As far as I can read of this I need to change the authentication type.

pglombardo commented 1 year ago

Cool. Great that you found the root cause. I found these on StackOverflow. It seems like you have to set auth to plain and starttls to true:

MkosterNet4it commented 1 year ago

Hey @pglombardo,

I changed some mail settings as I found we have another smtp server, right now i'm getting this message.

[2023-08-15T11:33:05.483034 #208] FATAL -- : [89bae59d-22d6-443d-9470-12c86ac42c93]
[89bae59d-22d6-443d-9470-12c86ac42c93] Net::ReadTimeout (Net::ReadTimeout with #<Socket:(closed)>):
[89bae59d-22d6-443d-9470-12c86ac42c93]
[89bae59d-22d6-443d-9470-12c86ac42c93] app/controllers/application_controller.rb:14:in `custom_set_locale_from_url'

This is a totally new message that I haven't seen before.

pglombardo commented 1 year ago

That means that the container couldn't transfer data over the network. But without more info, it's hard to tell where and why.

What did you do to get that error message? Could you post the full stack trace?

MkosterNet4it commented 1 year ago

Hey @pglombardo,

What I did was click on the button "Didn't receive confirmation instructions?" Please let me know how to post the full stack trace as the previous send message was the only thing I got when doing either vim and cat on the production.log

gregoryca commented 12 months ago

Sadly i'm having the same problem. I can post a stacktrace if needed.

I have tried a Azure Container Instance deployment, and a Azure App Service/Web App route. Both deployments worked fine (i deploy from terraform). When i enable the login functionality, and sign up it won't work because PWPush never sends the confirmation email. This also happens in my infra at home where i run docker(compose) on a plain linux machine. It keeps trying to send mail from port 25 while it should use port 465.

gregoryca commented 10 months ago

Is there by any chance any progress on this issue ? Thanks !

pglombardo commented 10 months ago

Hi @gregoryca -

Sorry to hear these issues are still happening for some.

Could you shell into the container, start a console (rails console) and run Rails.application.config.action_mailer.smtp_settings and post the filtered output here?

gregoryca commented 10 months ago

mail error rails The container keeps mailing over port 25, while i've specified a different port in my docker-compose. Same issue on my ACI

pglombardo commented 10 months ago

What's odd is that it says localhost and port 25 - neither of which are in your config.

Could you set both of the following environment variable for your container, restart it and then try the test again?

PWP__MAIL__SMTP_STARTTLS=false
PWP__MAIL__SMTP_ENABLE_STARTTLS_AUTO=false
pglombardo commented 10 months ago

Also why the literal quotes (\") in the username?

TargetCrafter commented 10 months ago

I get these same 500 errors in my container. I've tried the starttls settings and i also tried to get the Rails config, but i get the following error.

/opt/PasswordPusher $ Rail console
/bin/sh: Rail: not found
pglombardo commented 10 months ago

Hi @TargetCrafter - The command should be rails - lowercase and plural.

If you get a 500, find the error stack trace in the container log and post it here.

TargetCrafter commented 10 months ago

I got the following logs in docker: Errno::EADDRNOTAVAIL (Address not available - connect(2) for nil port 587)

I find this odd because i have configured to use port 2525 for smtp in my env file:

export PWP__MAIL_SMTP_ADDRESS='XXXXX'
export PWP__MAIL_SMTP_PORT=2525
export PWP__MAIL__RAISE_DELIVERY_ERRORS=true
export PWP__MAIL_SMTP_USER_NAME='XXXXX'
export PWP__MAIL_SMTP_PPASSWORD='XXXXX'
export PWP__MAIL__SMTP_AUTHENTICATION=plain
export PWP__MAIL__SMTP_STARTTLS=false
export PWP__MAIL__SMTP_ENABLE_STARTTLS_AUTO=false
export PWP__MAIL__MAILER_SENDER='"XXXXX" <XXXXX>'
pglombardo commented 10 months ago

@TargetCrafter there are some errors in your environment variable names. PWP__MAIL__ must always have double underscores.

These:

export PWP__MAIL_SMTP_ADDRESS='XXXXX'
export PWP__MAIL_SMTP_PORT=2525
export PWP__MAIL_SMTP_USER_NAME='XXXXX'
export PWP__MAIL_SMTP_PPASSWORD='XXXXX' # <--- also spelling error here 'ppassword'

should be

export PWP__MAIL__SMTP_ADDRESS='XXXXX'
export PWP__MAIL__SMTP_PORT=2525
export PWP__MAIL__SMTP_USER_NAME='XXXXX'
export PWP__MAIL__SMTP_PASSWORD='XXXXX'  

Documentation here if you want to copy paste for simplicity.

TargetCrafter commented 10 months ago

Thanks, that fixed it. And now I feel stupid xD

pglombardo commented 10 months ago

Thanks, that fixed it. And now I feel stupid xD

Excellent! But don't feel that way. Those env vars could definitely be more user friendly...

gregoryca commented 10 months ago

Excuse my for my late comment. I will make the changes, and see if that changes the behaviour. Why the quotes are being showed, is a good question and something i can't clarify sadly. I will try to create another mail address/display name.

Maybe it's the double quotes that's throwing me for a loop

pglombardo commented 4 months ago

Hi all - just an update on the email issues: in v1.39.8, I added a tool to test email configurations. Could you update to that version and try this out?

It should reveal exactly where the issue is...