decidim-install icon indicating copy to clipboard operation
decidim-install copied to clipboard

decidim not sending email

Open robertgarrigos opened this issue 6 years ago • 27 comments

I've followed the config doc https://github.com/Platoniq/decidim-install/blob/master/basic-config.md to config my own email server and it's not sending it, although decidim says it is. I have changed the port value in config/secrets.yml to the right one wiht no luck. How is decidim sending email? How can I check the logs?

robertgarrigos avatar Jul 18 '18 13:07 robertgarrigos

Check errors in the production log and paste them here:

grep ERROR log/production.log -A3 -B3

microstudi avatar Jul 18 '18 15:07 microstudi

E, [2018-07-18T18:51:35.456933 #1158] ERROR -- : [ActiveJob] [ActionMailer::DeliveryJob] [65fda941-1a9f-4d38-955d-e724db2761f0] Error performing ActionMailer::DeliveryJob (Job ID: 65fda941-1a9f-4d38-955d-e724db2761f0) from Async(mailers) in 60915.35ms: Net::ReadTimeout (Net::ReadTimeout):
/home/decidim/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/protocol.rb:181:in `rbuf_fill'
/home/decidim/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/protocol.rb:157:in `readuntil'
/home/decidim/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/protocol.rb:167:in `readline'

I thought it was firewall, so I disabled it, but still having this error.

robertgarrigos avatar Jul 18 '18 16:07 robertgarrigos

I believe where the problem is: decidim uses starttls to send secure mail thru a non-secure port. I've changed the port to 465, which is the secure port for smtp. I would need to add some settings about using TLS or SSL instead of STARTTLS, but I don't know where to set this.

robertgarrigos avatar Jul 18 '18 17:07 robertgarrigos

got it!

Added in /config/environments/production.rb:

config.action_mailer.smtp_settings = {
    :address        => Rails.application.secrets.smtp_address,
    :port           => Rails.application.secrets.smtp_port,
    :authentication => Rails.application.secrets.smtp_authentication,
    :user_name      => Rails.application.secrets.smtp_username,
    :password       => Rails.application.secrets.smtp_password,
    :domain         => Rails.application.secrets.smtp_domain,
    :enable_starttls_auto => Rails.application.secrets.smtp_starttls_auto,
    :openssl_verify_mode => 'none',
    :ssl =>                   true,
    :tls =>                  true
  }

and now it's working

robertgarrigos avatar Jul 18 '18 17:07 robertgarrigos

That's great! I will link this issue from the doc in the Mail debug section

microstudi avatar Jul 18 '18 17:07 microstudi

I also can't achieve to send messages from Decidim. This are my log latest entries:

D, [2019-02-14T09:50:54.511985 #21520] DEBUG -- : Delayed::Backend::ActiveRecord::Job Load (1.1ms) UPDATE "delayed_jobs" SET locked_at = '2019-02-14 08:50:54.510223', locked_by = 'delayed_job host:decidim pid:21520' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2019-02-14 08:50:54.509491' AND (locked_at IS NULL OR locked_at < '2019-02-14 04:50:54.509546') OR locked_by = 'delayed_job host:decidim pid:21520') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *

Also a GREP for the term ERROR:

decidim@decidim:~/decidim-app$ grep ERROR log/production.log -A3 -B3

----==_mimepart_5c6500aecb3ac_1c092aed689952c09355--

E, [2019-02-14T06:46:23.215804 #7177] ERROR -- : [ActiveJob] [ActionMailer::DeliveryJob] [7bfc0912-9a79-48bf-a73e-3ea8158f2785] Error performing ActionMailer::DeliveryJob (Job ID: 7bfc0912-9a79-48bf-a73e-3ea8158f2785) from Async(mailers) in 1130.77ms: Errno::ECONNREFUSED (Connection refused - connect(2) for nil port 587): /home/decidim/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:539:in initialize' /home/decidim/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:539:in open' /home/decidim/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:539:in `tcp_socket'

----==_mimepart_5c6501cf9e282_1c092aed689952c096f6--

E, [2019-02-14T06:51:11.661332 #7177] ERROR -- : [ActiveJob] [ActionMailer::DeliveryJob] [8604e7cf-fc32-424d-8375-0eaf0ca94e24] Error performing ActionMailer::DeliveryJob (Job ID: 8604e7cf-fc32-424d-8375-0eaf0ca94e24) from Async(mailers) in 1083.03ms: Errno::ECONNREFUSED (Connection refused - connect(2) for nil port 587): /home/decidim/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:539:in initialize' /home/decidim/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:539:in open' /home/decidim/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:539:in `tcp_socket'

Do you have any idea? Thank's!

polnetwork avatar Feb 14 '19 08:02 polnetwork

@polnetwork can you access port 587? for example with comman:

nc -zv smtp.server.tld 587

microstudi avatar Feb 14 '19 10:02 microstudi

Yes Connection to smtp.gmail.com 587 port [tcp/submission] succeeded! I'v created a specific PWD for the app (as yout told here https://github.com/Platoniq/decidim-install/blob/master/basic-config.md), and also tried with my own SMTP server. How can I force to retry message cue processing after a setup change? Thank you

polnetwork avatar Feb 14 '19 10:02 polnetwork

It's possible your suffering from an error with IPv6 with gmail stmp. Have you tried what's explained in basic-config about disabling IPv6? image

microstudi avatar Feb 14 '19 10:02 microstudi

Yes, i'd done that:

sudo sysctl -p net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1

I'm testing with other server/ports configurations. What's the best wsy to test if the system is sending messages? Now I'm creating users throught admin to test it.

Thank's again :-)

polnetwork avatar Feb 14 '19 10:02 polnetwork

The easiest way is to just to click the "lost password" link in login.

If you are using active job, can you share this result?

RAILS_ENV=production bin/delayed_job status

microstudi avatar Feb 14 '19 10:02 microstudi

decidim@decidim:~/decidim-app$ RAILS_ENV=production bin/delayed_job status delayed_job: running [pid 1304]

but still not sending emails.

Here latest ERROR log entries

----==_mimepart_5c654cdd667b2_4892ab2a2cbbaf4654c5--

E, [2019-02-14T12:11:25.439015 #1161] ERROR -- : [ActiveJob] [ActionMailer::DeliveryJob] [edbeb81a-96ba-4f5b-8dd0-8d44ba5a8294] Error performing ActionMailer::DeliveryJob (Job ID: edbeb81a-96ba-4f5b-8dd0-8d44ba5a8294) from Async(mailers) in 1097.45ms: OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv3/TLS write client hello: wrong version number): /home/decidim/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/protocol.rb:44:in connect_nonblock' /home/decidim/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/protocol.rb:44:in ssl_socket_connect' /home/decidim/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:584:in `tlsconnect'

----==_mimepart_5c654ce490ccb_4892ab2a2cbbaf4657f1--

E, [2019-02-14T12:11:32.620482 #1161] ERROR -- : [ActiveJob] [ActionMailer::DeliveryJob] [f86076ac-56b7-4d93-a99d-b913d14a87ce] Error performing ActionMailer::DeliveryJob (Job ID: f86076ac-56b7-4d93-a99d-b913d14a87ce) from Async(mailers) in 302.54ms: OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv3/TLS write client hello: wrong version number): /home/decidim/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/protocol.rb:44:in connect_nonblock' /home/decidim/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/protocol.rb:44:in ssl_socket_connect' /home/decidim/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:584:in `tlsconnect'

polnetwork avatar Feb 14 '19 11:02 polnetwork

It seems that something is wrong with the SSL configuration, can you tell me if your this parts of your config/application.yml:

SMTP_ADDRESS: smtp.gmail.com
SMTP_DOMAIN: gmail.com

And config/secrets.yml:

production:
  <<: *default
...
  smtp_domain: <%= ENV["SMTP_DOMAIN"] %>
  smtp_port: "587"
  smtp_starttls_auto: true
  smtp_authentication: "plain"

Matchs your configuration?

microstudi avatar Feb 14 '19 11:02 microstudi

This is exactly my setup, I'v tryed with main gmail pwd and also with a secondary password. Thanks again.

polnetwork avatar Feb 14 '19 12:02 polnetwork

From here: https://gist.github.com/mislav/5026283 Maybe you need root certificates installed?

apt-get install ca-certificates

microstudi avatar Feb 14 '19 12:02 microstudi

apt-get install ca-certificates

Already installed...

polnetwork avatar Feb 14 '19 12:02 polnetwork

I'm finally able to send messages, I'v fixed it following this: https://coderwall.com/p/ubl6iw/fix-ssl_connect-returned-1-errno-0-state-sslv3-read-server-certificate-b-certificate-verify-failed-openssl-ssl-sslerror Hope this helps someone :-)

polnetwork avatar Feb 14 '19 15:02 polnetwork

thanks pol!

microstudi avatar Feb 14 '19 16:02 microstudi

I can't send messages from Decidim: These are my last error logs

Screenshot_2

I have verified that you can access port 587. I have disabled IPv6, as suggested in the manual. It passed you part of the application.yml and secrets.yml configuration:

Screenshot_5

Screenshot_4

javims90 avatar May 25 '20 11:05 javims90

Are you sure that you can use office365 for this? I don't have experience with it

microstudi avatar May 25 '20 13:05 microstudi

Been reading and looking for information and I think you can't. Also thank you very much for your help.

javims90 avatar May 25 '20 13:05 javims90

You should be able to do it with Office365 as well: https://docs.microsoft.com/en-us/exchange/mail-flow-best-practices/how-to-set-up-a-multifunction-device-or-application-to-send-email-using-microsoft-365-or-office-365

If nothing else, the option 3 (relay) will work.

I would not suggest using something like this in production, though. It has some limitations.

ahukkanen avatar Jul 17 '20 07:07 ahukkanen

Hi

I installed Decidim using the automated script recommended by Platoniq's documentation https://github.com/Platoniq/decidim-install ./install-decidim.sh -u [email protected] -p some-password my-decidim and i ran perfect with no error

I continued with basic configuration here https://github.com/Platoniq/decidim-install/blob/master/basic-config.md

I didn't set SSL up

I am using gmail as my SMTP provider.

I am confident that the issue is not a typo in my decidim.rb, and application.yml files.

I set up my gmail settings allow less secure apps.

Everything looks OK since the command grep ERROR ~/decidim-app/log/production.log -A3 -B3 gives following result : Fichier binaire /home/pretdegilles/decidim-app/log/production.log correspondant

Telnet smtp.gmail.com 587 answers "connected" nc -zv smtp.server.tld 587 answers "nc: getaddrinfo for host "smtp.server.tld" port 587: Name or service not known"

Could you tell me what's wrong with my config ?

Help appreciated since our village decided to use decidim in order to help for democraty

gillesdeloustal avatar Mar 23 '21 23:03 gillesdeloustal

smtp.server.tld ? where do you get this from ?

microstudi avatar Mar 24 '21 17:03 microstudi

Hi I found smtp.server.tld in the 8th post above.

Anyway, I re-installed Lubuntu on a i386 machine and decidim with the automated script, giving system admin same user and password as gmail's I have no mail server installed neither apache I didn't set SSL up, I am using gmail as my SMTP provider, I made several try with "an application specific password" and "less secure applications", I unlocked Captcha before I key enter on the organization page. The command grep ERROR ~/decidim-app/log/production.log -A3 -B3 returned ----==_mimepart_605c9d5ae8958_77e1fe6e43421--

E, [2021-03-25T15:25:33.735724 #1918 (External link)] ERROR -- : [ActiveJob] [ActionMailer::DeliveryJob] [2dbeae08-3fe3-444e-8b2f-468b2516130e] Error performing ActionMailer::DeliveryJob (Job ID: 2dbeae08-3fe3-444e-8b2f-468b2516130e) from Async(mailers) in 3772.25ms: Net::SMTPAuthenticationError (535-5.7.8 Username and Password not accepted.

I'm sure having writen gmail's user and password correctly in the organization page as well as in application.yml

Thank you for taking my question into account.

gillesdeloustal avatar Mar 30 '21 21:03 gillesdeloustal

Hello

my decidim does not send starttls anymore, but in organization I have port 587 here the error E, [2021-05-13T06:27:04.023561 #817] ERROR -- : [ActiveJob] [ActionMailer::DeliveryJob] [feeeb8ab-ccd9-459f-be67-7a621b4ed71c] Error performing ActionMailer::DeliveryJob (Job ID: feeeb8ab-ccd9-459f-be67-7a621b4ed71c) from Async(mailers) in 510.03ms: Net::SMTPAuthenticationError (530 5.7.0 Must issue a STARTTLS command first ):

it is like enable_starttls_auto=>true is lost in database, b/c if I do it by console, it works fine:

Loading production environment (Rails 5.2.5) irb(main):001:0> irb(main):002:0> mailer = ActionMailer::Base.new irb(main):003:0> mailer.delivery_method => :smtp irb(main):004:0> mailer.smtp_settings => {:address=>"mail.possibile.com", :port=>"587", :authentication=>"plain", :user_name=>"...........", :password=>".........", :domain=>"possibile.com", :enable_starttls_auto=>true, :openssl_verify_mode=>"none"} irb(main):005:0> mailer.mail(from: '[email protected]', to: '[email protected]', subject: 'test', body: "Hello, you've got mail!").deliver Sent mail to [email protected] (997.8ms) Date: Thu, 13 May 2021 06:50:35 +0200 From: [email protected] To: [email protected] Message-ID: [email protected] Subject: test Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit

Hello, you've got mail! => #<Mail::Message:390520, Multipart: false, Headers: <Date: Thu, 13 May 2021 06:50:35 +0200>, <From: [email protected]>, <To: [email protected]>, <Message-ID: [email protected]>, <Subject: test>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <Content-Transfer-Encoding: 7bit>> irb(main):006:0>

can you help me? 10x

mauriziomarini avatar May 13 '21 04:05 mauriziomarini

Hi I found smtp.server.tld in the 8th post above. smtp.server.tld is a placeholder, something to be changed with what does fit your configuration If you are using gmail change it accordingly sed -i -e s/smtp.server.tld/smtp.gmail.com/g whatever.yml

mauriziomarini avatar May 13 '21 10:05 mauriziomarini