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

503 5.5.1 Error: authentication not enabled when I'm running a local SMTP server. #1657

Closed
virtadpt opened this issue Aug 29, 2016 · 18 comments

Comments

@virtadpt
Copy link
Collaborator

I have Postfix installed on my Huginn server, and it is configured to only send outbound mail from applications running on the server (alongside several other pieces of software). After updating last night I started getting failed jobs with the following error message:

503 5.5.1 Error: authentication not enabled

The relevant configuration settings in huginn/.env, which I have not edited (confirmed with the output of AIDE):

SMTP_DOMAIN=my.huginn.server.com
SMTP_USER_NAME=
SMTP_PASSWORD=
SMTP_SERVER=localhost
SMTP_PORT=25
SMTP_AUTHENTICATION=plain
SMTP_ENABLE_STARTTLS_AUTO=false

Did something change in Huginn that prevents it from using the local SMTP server without authentication?

@cantino
Copy link
Member

cantino commented Aug 30, 2016

Hey @virtadpt. The only thing that comes to mind is #1595. You could try editing lines 7 and 8 of action_mailer.rb to be ENV['SMTP_USER_NAME'], and ENV['SMTP_PASSWORD'] (remove the || ""). It's possible that you need nil, not empty string, to be sent to the mail server?

@virtadpt
Copy link
Collaborator Author

Thanks, let me give that a try...

@virtadpt
Copy link
Collaborator Author

No dice. Let me try 'nil'.

@virtadpt
Copy link
Collaborator Author

'nil' didn't work, either.

Hypothetically speaking, what would happen if authentication: ENV['SMTP_AUTHENTICATION'] || "plain", was set to 'nil'?

@virtadpt
Copy link
Collaborator Author

Per the answer here (https://stackoverflow.com/questions/26093514/rails-actionmailer-send-email-without-authentication) I had to comment out (not set to 'nil' - that continued to throw the same error) the authentication, user_name, and password lines to get outbound SMTP working again.

Perhaps it should be possible to set the appropriate lines in huginn/.env to nothing (e.g., "SMTP_AUTHENTICATION=") to disable that particular facet of SMTP transmission... or would ActionMailer not permit that by design?

@cantino
Copy link
Member

cantino commented Aug 30, 2016

Interesting. Does the following work if you set SMTP_AUTHENTICATION to none?

authentication: ENV['SMTP_AUTHENTICATION'] == 'none' ? nil : (ENV['SMTP_AUTHENTICATION'] || "plain")

and

user_name: ENV['SMTP_USER_NAME'].presence,
password: ENV['SMTP_PASSWORD'].presence,

work?

If it doesn't, then I think you're correct, and the existence of the key, independent of it's value is what's causing authentication. In that case, we should do:

ActionMailer::Base.smtp_settings = {}.tap do |settings|
  settings.merge!({
    address: ENV['SMTP_SERVER'] || "smtp.gmail.com",
    port: ENV['SMTP_PORT'] || 587,
    domain: ENV['SMTP_DOMAIN'],
    enable_starttls_auto: ENV['SMTP_ENABLE_STARTTLS_AUTO'] == 'true',
    openssl_verify_mode: ENV['SMTP_OPENSSL_VERIFY_MODE'].presence,
    ca_path: ENV['SMTP_OPENSSL_CA_PATH'].presence,
    ca_file: ENV['SMTP_OPENSSL_CA_FILE'].presence
  })
  if ENV['SMTP_AUTHENTICATION'] != 'none'
    settings.merge!({
      authentication: ENV['SMTP_AUTHENTICATION'].presence || "plain",
      user_name: ENV['SMTP_USER_NAME'].presence,
      password: ENV['SMTP_PASSWORD'].presence
    })
  end
end

@virtadpt
Copy link
Collaborator Author

I'm trying it right now. I'l keep an eye on things, and if I keep getting e-mail in the next hour or two, that might be the fix.

@dsander
Copy link
Collaborator

dsander commented Aug 30, 2016

@virtadpt I used your .env settings and compared the old and the new ActionMailer SMTP configuration and think the first change Andrew proposed should have worked:

# New:
{:address=>"localhost",
 :port=>"25",
 :domain=>"my.huginn.server.com",
 :authentication=>"plain",
 :enable_starttls_auto=>false,
 :user_name=>"",
 :password=>"",
 :openssl_verify_mode=>nil,
 :ca_path=>nil,
 :ca_file=>nil}
# Old
{:address=>"localhost",
 :port=>25,
 :domain=>"my.huginn.server.com",
 :authentication=>"plain",
 :enable_starttls_auto=>false,
 :user_name=>nil,
 :password=>nil,
 :openssl_verify_mode=>nil,
 :ca_path=>nil,
 :ca_file=>nil}

I think it should work to change config/initializers/action_mailer.rb to:

ActionMailer::Base.smtp_settings = {
  address: ENV['SMTP_SERVER'] || "smtp.gmail.com",
  port: ENV['SMTP_PORT'] || 587,
  domain: ENV['SMTP_DOMAIN'],
  authentication: ENV['SMTP_AUTHENTICATION'] || "plain",
  enable_starttls_auto: ENV['SMTP_ENABLE_STARTTLS_AUTO'] == 'true',
  user_name: ENV['SMTP_USER_NAME'].presence,
  password: ENV['SMTP_PASSWORD'].presence,
  openssl_verify_mode: ENV['SMTP_OPENSSL_VERIFY_MODE'].presence,
  ca_path: ENV['SMTP_OPENSSL_CA_PATH'].presence,
  ca_file: ENV['SMTP_OPENSSL_CA_FILE'].presence
}

@virtadpt
Copy link
Collaborator Author

@cantino Just tried the changes you suggested - no soap, no outbound SMTP.

@dsander Just set things up the way you suggested with SMTP_AUTHENTICATION= in huginn/.env. Let's see what happens.

@virtadpt
Copy link
Collaborator Author

virtadpt commented Aug 30, 2016

EDITED: It took a while, but a couple of e-mails finally made it though.

@cantino
Copy link
Member

cantino commented Aug 31, 2016

So the change @dsander suggested seems to have fixed it, @virtadpt?

@virtadpt
Copy link
Collaborator Author

virtadpt commented Sep 1, 2016

That seems to have fixed it. Note that in the .env file SMTP_USERNAME, SMTP_PASSWORD, and SMTP_AUTHENTICATION must have nothing after the equals sign for it to work, putting something like nil or false won't work. It'll be a minor edit to the comments of huginn/.env.example.

dsander added a commit to dsander/huginn that referenced this issue Sep 1, 2016
`user_name` and `password` need to be set to nil when no authentication should be performed

Fixes huginn#1657
@a10kiloham
Copy link
Contributor

a10kiloham commented Oct 26, 2017

Strangely after moving to docker but keeping all my old configuration in getting this error. Postfix is configured the same and the docker network is bridged properly but no matter how I configure it huginn is making an AUTH request to postfix putting u this same error. any other ideas why this might affect from docker?

   503 5.5.1 Error: authentication not enabled

/usr/lib/ruby/2.4.0/net/smtp.rb:981:in `check_auth_response'
/usr/lib/ruby/2.4.0/net/smtp.rb:736:in `auth_plain'
/usr/lib/ruby/2.4.0/net/smtp.rb:728:in `authenticate'
/usr/lib/ruby/2.4.0/net/smtp.rb:565:in `do_start'
/usr/lib/ruby/2.4.0/net/smtp.rb:518:in `start'
ENV SMTP_DOMAIN=mysite.info
ENV SMTP_USER_NAME=
ENV SMTP_PASSWORD=
ENV SMTP_SERVER=127.0.0.1
ENV SMTP_PORT=25
ENV SMTP_AUTHENTICATION=none
ENV SMTP_ENABLE_STARTTLS_AUTO=false
ENV EMAIL_FROM_ADDRESS=huginn@mysite.info

@dsander
Copy link
Collaborator

dsander commented Oct 26, 2017

How did you configure the network bridge? I am surprised that the docker container can reach the docker host by using 127.0.0.1.

@a10kiloham
Copy link
Contributor

a10kiloham commented Oct 26, 2017 via email

@a10kiloham
Copy link
Contributor

The docker commands are

 --net=host -h 127.0.0.1 -p 127.0.0.1:3000:3000 

I dump all my ENV variables into a Dockerfile and rebuild an image. Easier for me to automate this way vs 20+ env variables in my run command.

The container is interfacing fine with postfix but it always seems to send an AUTH request.
Separately, I also can't send via Gmail either as it gives me an end of file error when I use the same SSL config as several other apps on this PC :/

@a10kiloham
Copy link
Contributor

FWIW, I seem to have fixed this by finding that pull from earlier this year to specify SMTP_AUTHENTICATION=none as an env variable. This seems to have been overlooked in docs so I'll note this elsewhere in the wiki.

@dsander
Copy link
Collaborator

dsander commented Oct 27, 2017

The docker commands are

--net=host -h 127.0.0.1 -p 127.0.0.1:3000:3000

Cool I did not know this was possible.

I dump all my ENV variables into a Dockerfile and rebuild an image. Easier for me to automate this way vs 20+ env variables in my run command.

Interesting, you can also use the docker run --env-file to pass in variables from an external .env file.

This seems to have been overlooked in docs so I'll note this elsewhere in the wiki.

Thank you! We are not very good when it comes to documenting stuff 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants