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
2.12k stars 359 forks source link

Smtp validation loads always localhost #2001

Closed slim-azaiz closed 1 month ago

slim-azaiz commented 8 months ago

🐛 Bug Report

I tried to test smtp validation, but it gets always localhost as server smtp even if i have well configured the settings.yml

🔬 How To Reproduce

Steps to reproduce the behavior:

Code sample

./bin/rails console
Rails.application.config.action_mailer.smtp_settings

=>

{:address=>"server",
 :port=>24,
 :user_name=>nil,
 :password=>nil,
 :authentication=>"plain",
 :enable_starttls_auto=>true,
 :open_timeout=>10,
 :read_timeout=>10}
Mail.deliver do
  to '<mail>'
  from 'user'
  subject 'testing mail'
  body 'testing mail'
end
/opt/PasswordPusher/vendor/bundle/ruby/3.2.0/gems/net-smtp-0.4.0.1/lib/net/smtp.rb:631:in `initialize': Connection refused - connect(2) for "localhost" port 25 (Errno::ECONNREFUSED)
github-actions[bot] commented 8 months ago

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

pglombardo commented 8 months ago

Hi @slim-azaiz - Thanks for reporting. I will take a close look at this soon. I know email is a problem for a subset of users and I haven't figured out why yet. I'll post back soon.

pglombardo commented 7 months ago

Hi @slim-azaiz - in v1.39.8, I added a tool to better flush out email issues. Could you update to that version and try this out? It should hopefully point us in the right direction.

slim-azaiz commented 7 months ago

Hello, It is working better but i can not connect to the server without authentication

{:address=>"<server_url>",
 :port=>25,
 :user_name=>"",
 :password=>"",
 :authentication=>"plain",
 :enable_starttls_auto=>nil,
 :open_timeout=>10,
 :read_timeout=>10,
 :domain=>"mousquetaires.com",
 `:openssl_verify_mode=>:none}`

I got this errror /opt/PasswordPusher/vendor/bundle/ruby/3.2.0/gems/net-smtp-0.5.0/lib/net/smtp/authenticator.rb:45:in `finish': 500 5.5.1 Command unrecognized: "AUTH PLAIN AAA=" (Net::SMTPAuthenticationError) irb(main):002> Rails.application.config.action_mailer.smtp_settings

pglombardo commented 7 months ago

Cool that is progress. This problem points to :authentication. Try setting it to nil or not setting it at all.

Here are the docs for :authentication:

:authentication - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of :plain (will send the password in the clear), :login (will send password Base64 encoded) or :cram_md5 (combines a Challenge/Response mechanism to exchange information and a cryptographic Message Digest 5 algorithm to hash important information)

slim-azaiz commented 7 months ago

Hello,

Thanks @pglombardo for your quick reponse. I have already tried nil( i deleted the parameter from setting file ) and falsebut i got always the same error.

I think that authentication field has default value that can not be redefined.

Regards, Slim

slim-azaiz commented 7 months ago

I am wondering if there is a bug in authentication field ?

pglombardo commented 7 months ago

Hi @slim-azaiz - In the latest releases I removed the defaults. Did you try with the latest tag yet? The update where I removed the defaults was in v1.40.7.

I think I neglected to update here. Apologies - it's a bit crazy here this week.

slim-azaiz commented 7 months ago

Hello,

I am using the latest version 1.40.10

{:address=>"<server_url>",
 :port=>25,
 :domain=>"<domain>",
 :open_timeout=>10,
 :read_timeout=>10,
 :openssl_verify_mode=>:none}
irb(main):002>
irb(main):003> TestMailer.send_test_email(<mail>).deliver_now
/opt/PasswordPusher/app/mailers/test_mailer.rb:7:in 
send_test_email : No SMTP username provided: smtp_user_name (StandardError)

There is no more the authentification field neither enable_starttls_auto

Regards, Slim

pglombardo commented 7 months ago

Hey @slim-azaiz - what type of mail server are you using and how is it configured?

slim-azaiz commented 6 months ago

It is an smtp server. I am using the last version 1.40.14 smtp_user_name is still mandatory

app/mailers/test_mailer.rb:7:in `send_test_email': No SMTP username provided: smtp_user_name (StandardError)
        from (irb):3:in `<main>'
LukaszC86 commented 5 months ago

I have the same issue with the latest version. I have internal server without authentication and currently it's impossible to deliver any messages, because bloody authentication is always turned on:

Failed delivery of mail 666c12f698020_e385a4522f3@85d8d8368e07.mail error_class=ArgumentError error_message="SMTP-AUTH requested but missing user name"

Update: I'm sorry, I've noticed your commit @pglombardo to the settings.yml and I've mounted my custom settings file to the container with commented out "#smtp_authentication: 'plain'" - it works perfectly now. 🥳🥳🥳

pglombardo commented 5 months ago

@LukaszC86 - that is very welcome news as this issue has driven me crazy. 😄

@slim-azaiz - have you had a chance to try the latest releases?

burghoffdavid commented 4 months ago

Having the same issue as @slim-azaiz .

TestMailer output:

app/mailers/test_mailer.rb:7:in `send_test_email': No SMTP username provided: smtp_user_name (StandardError)

smtp_settings

irb(main):002>  Rails.application.config.action_mailer.smtp_settings
=>
{:address=>"192.168.120.254",
 :port=>25,
 :open_timeout=>10,
 :read_timeout=>10,
 :openssl_verify_mode=>:none,
 :enable_starttls_auto=>false}

settings.yml

Only thing i replaced was the domain in mailer_sender and removed some comments to keep it short.

mail:
  raise_delivery_errors: true
  smtp_address: '192.168.120.254'
  smtp_port: 25

  # Important: Comment this out if your server doesn't require authentication.
  # smtp_authentication: login

  # smtp_user_name: ""
  # smtp_password: ""

  smtp_starttls: false
  smtp_enable_starttls_auto: false

  smtp_open_timeout: 10
  smtp_read_timeout: 10
  smtp_openssl_verify_mode: 'none'

  mailer_sender: '"Password Pusher" <no-reply@domain.de>'

docker logs

When attempting to reset password from web interface

[17] - Worker 1 (PID: 26) booted in 0.01s, phase: 0
I, [2024-07-08T14:54:28.267256 #22]  INFO -- : [949620b3-cf28-4f5d-b9eb-52cfd8abcc0a] method=GET path=/de/Benutzer/password/neu format=html controller=Users::PasswordsController action=new status=200 allocations=38175 duration=220.41 view=47.21 db=17.23 ip=192.168.121.86
I, [2024-07-08T14:54:33.922910 #22]  INFO -- : [7b25ca7f-b8a4-42f5-a7e8-48e434ea1e6b] method=POST path=/de/Benutzer/password format=turbo_stream controller=Users::PasswordsController action=create status=500 allocations=9857 duration=942.02 view=0.00 db=319.54 ip=192.168.121.86
E, [2024-07-08T14:54:33.926226 #22] ERROR -- : [7b25ca7f-b8a4-42f5-a7e8-48e434ea1e6b]
[7b25ca7f-b8a4-42f5-a7e8-48e434ea1e6b] EOFError (end of file reached):
[7b25ca7f-b8a4-42f5-a7e8-48e434ea1e6b]
[7b25ca7f-b8a4-42f5-a7e8-48e434ea1e6b] app/controllers/application_controller.rb:18:in `custom_set_locale_from_url'
burghoffdavid commented 4 months ago

Nevermind, it was a misconfigured SMTP server, the IP was blacklisted. Now everything works like a charm. Nevertheless, I think the TestMailer expects the smtp_user_name and smtp_password. Also a more descriptive error message could help users here.

Love the project btw, good stuff! ❤️

pglombardo commented 4 months ago

Also a more descriptive error message could help users here.

Agree for sure. It's a 3rd party library that has been hard to deal with. :-/

Thanks for the nice word and glad it's working now!

Also for everyone else, the wiki has been disabled and replaced with a new documentation portal.

The email diagnosis page is now here: https://docs.pwpush.com/docs/troubleshooting-email/

pglombardo commented 4 months ago

@slim-azaiz - any update from your side? I'll close this issue eventually unless you still need help/are having issues...

pglombardo commented 1 month ago

Closing. If anything remains, please feel free to file another issue!