Mail server configuration

Hi everyone! @marito59 seems to manage to move forward on some staging installation for the French instance, but we still have a problem with the email, we don’t receive them, so we can’t validate any entreprise… I remember we had the same problem and @RohanM you did something and then we received them all… they were stuck somewhere… do you remember? Any tip?
@marito59 if you want to add some explanation about the web server configuration maybe that will help identify the source of the issue :wink:

Hi @MyriamBoure, @marito59!

There’s a couple of things that could be stopping mail from sending. The first thing to check is if the delayed job worker is running, and if it’s processing jobs. Is there a backlog of jobs? You can check in the console with:

Delayed::Job.count

That number should be zero (or very close to zero). If it’s not, then the delayed job worker might not be running for some reason. If that’s the case, let me know and I can help with setting it up. As a starting point, here’s the part of the provisioning script that’s concerned with setting up delayed job:

Hi @RohanM, @MyriamBoure

The Delayed Job count is zero. Checked both in the database and console. The config is OK with Sendgrid since I am receiving the test email.What else should I verify ?

The script is running. The delayed_job.log seems OK, too. The task is present and completed.

@RohanM investigating the topic, I see that there is a standard spree issue on email configuration. did you do something around this kind of topics ? see https://guides.spreecommerce.com/user/configuring_mail_methods.html. do we have to install spree_mail_settings ? it does not seem to be in the gemfile. see https://spreecommerce.com/blog/send-email-with-spree. or either do this : https://stackoverflow.com/questions/17063241/spree-mail-method-is-not-working ?

confusing … :anguished:

Hi @marito59,

To add to the confusion, we’re using quite an old version of spree (v1.3). I believe this version is before spree_mail_settings was split out into a gem. So you should be able to find the mail settings in the admin interface under Configuration -> Mail Methods. Could you have a look in there and check if the correct configuration for SendGrid is present?

Also, you mentioned that you received a test email. Where was that test email sent from? It’d be useful to know which parts are verified to be working and which are uncertain.

for the ofn_development vagrant env, should settings of localhost, localhost, 25, none, none, vagrant, vagrant work? Or should I be using gmail or some other service?

I have a Delayed job count of 2. Possibly from mail trying to be sent before I had configured a mail method.

sadly @RohanM is now on holiday again for 10 days and I am pretty useless - but I would definitely try setting up a gmail account from admin/config. I have gmail accounts running both our staging and production servers, will send you a screengrab of the settings in staging as private message, hopefully that might help

We’ve used Mandrill for the UK servers, it gives all the settings that need to be plugged into the Spree admin form.

@RohanM, @Kirsten,@pmackay : the email I received was sent via the test email button of the Admin interface thru a Sendgrid account. Sendgrid have seen the email. Therefore, I guess the configuration itself is right. I am using a staging Ubuntu 14.04 server.

1 Like

Does the Rails server and Spree use a mail program within the underlying OS to send the mail, that might make sense to test via the command line?

We are still stuck with the mail server issue. Can anyone help ?

To refresh the topic :

  • mails are correctly sent and received in a mailbox from the Admin Interface
  • the delayed_job process is running and the items have been emptied from the database

Any clues ?

Hi @marito59,

Have you seen this thread? @maikel and I tracked down some mail issues on the UK server and wrote up our solutions, perhaps one of those would be useful?

Here is an update on the case:

  1. I don’t thinh the pb that you mentioned @RohanM is related.
  2. Digging more into my server, I noticed that the emails are there in tmp/letter_opener
  3. however, the site is started as a staging server with unicorn (see below)

I have tried to modify config/environments/staging.rb to add

config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: 'smtp.sendgrid.net', port: 587, domain: 'openfoodfrance.fr', user_name: <name>, password: <pass>, authentication: 'plain', enable_starttls_auto: true }

but with no effect so far.

Let me know if it gives you more clues.

Pinging @gnollet and @MyriamBoure

Folliwing the information provided in http://community.openfoodnetwork.org/t/need-help-to-fix-err-500/ I have managed to progress but the email is still not working.

Setting up monit and modifying delayed_job.sh to get the right path changed the behavior. letter_opener is no longer used. The fact was that I was launching delayed_job directly and the RAILS_ENV variable was missing. Now, it correctly set in monit script. By default, the development parameters were taken.

I now have an error related to config.action_mailer.default_url_options stating that the host variable was missing. I have tried several things with no success:

  • with config/initializers/spree.rb and config.override_actionmailer_config = true, the mail methods menu appears and there is no way to set the host variable.
  • with config.override_actionmailer_config = false, the menu is not present and I configure the smtp parameters in config/environments/staging.rb as described in previous message, adding config.action_mailer.default_url_options = { :host => "staging.openfoodfrance.fr" } in order to define the missing :host variable.

Neither options are working.

After each changes, service monit and unicorn_openfoodnetwork have been stopped and started.

Any clues ?

Below is the full error message in delayed_jobs table:

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true /home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_dispatch/http/url.rb:25:inurl_for’
/home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_dispatch/routing/route_set.rb:598:in url_for' /home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_dispatch/routing/route_set.rb:342:inurl_for’
/home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_dispatch/routing/route_set.rb:216:in enterprise_confirmation_url' /home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_dispatch/routing/routes_proxy.rb:29:inenterprise_confirmation_url’
/home/offrance/.gem/ruby/1.9.1/gems/devise-2.2.8/lib/devise/controllers/url_helpers.rb:50:in confirmation_url' /home/offrance/apps/openfoodnetwork/current/app/views/enterprise_mailer/confirmation_instructions.html.haml:12:in_4176988edea31748b7f51c4657881aaa’
/home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_view/template.rb:145:in block in render' /home/offrance/.gem/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/notifications.rb:125:ininstrument’
/home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_view/template.rb:143:in render' /home/offrance/.gem/ruby/1.9.1/bundler/gems/deface-1110a1336252/lib/deface/action_view_extensions.rb:41:inrender’
/home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_view/renderer/template_renderer.rb:47:in block (2 levels) in render_template' /home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_view/renderer/abstract_renderer.rb:38:inblock in instrument’
/home/offrance/.gem/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/notifications.rb:123:in block in instrument' /home/offrance/.gem/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/notifications/instrumenter.rb:20:ininstrument’
/home/offrance/.gem/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/notifications.rb:123:in instrument' /home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_view/renderer/abstract_renderer.rb:38:ininstrument’
/home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_view/renderer/template_renderer.rb:46:in block in render_template' /home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_view/renderer/template_renderer.rb:54:inrender_with_layout’
/home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_view/renderer/template_renderer.rb:45:in render_template' /home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_view/renderer/template_renderer.rb:18:inrender’
/home/offrance/.gem/ruby/1.9.1/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:150:in block in render_with_newrelic' /home/offrance/.gem/ruby/1.9.1/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/method_tracer.rb:69:inblock in trace_execution_scoped’
/home/offrance/.gem/ruby/1.9.1/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/method_tracer_helpers.rb:82:in trace_execution_scoped' /home/offrance/.gem/ruby/1.9.1/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/method_tracer.rb:67:intrace_execution_scoped’
/home/offrance/.gem/ruby/1.9.1/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:149:in render_with_newrelic' /home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_view/renderer/renderer.rb:36:inrender_template’
/home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/action_view/renderer/renderer.rb:17:in render' /home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/abstract_controller/rendering.rb:110:in_render_template’
/home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/abstract_controller/rendering.rb:103:in render_to_body' /home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/abstract_controller/rendering.rb:88:inrender’
/home/offrance/.gem/ruby/1.9.1/gems/actionmailer-3.2.21/lib/action_mailer/base.rb:713:in block in collect_responses_and_parts_order' /home/offrance/.gem/ruby/1.9.1/gems/actionmailer-3.2.21/lib/action_mailer/base.rb:724:ineach’
/home/offrance/.gem/ruby/1.9.1/gems/actionmailer-3.2.21/lib/action_mailer/base.rb:724:in each_template' /home/offrance/.gem/ruby/1.9.1/gems/actionmailer-3.2.21/lib/action_mailer/base.rb:709:incollect_responses_and_parts_order’
/home/offrance/.gem/ruby/1.9.1/gems/actionmailer-3.2.21/lib/action_mailer/base.rb:648:in mail' /home/offrance/.gem/ruby/1.9.1/gems/roadie-rails-1.0.3/lib/roadie/rails/automatic.rb:5:inmail’
/home/offrance/.gem/ruby/1.9.1/gems/devise-2.2.8/lib/devise/mailers/helpers.rb:16:in devise_mail' /home/offrance/apps/openfoodnetwork/current/app/mailers/enterprise_mailer.rb:19:inconfirmation_instructions’
/home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/abstract_controller/base.rb:167:in process_action' /home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/abstract_controller/base.rb:121:inprocess’
/home/offrance/.gem/ruby/1.9.1/gems/actionpack-3.2.21/lib/abstract_controller/rendering.rb:45:in process' /home/offrance/.gem/ruby/1.9.1/gems/actionmailer-3.2.21/lib/action_mailer/base.rb:459:inprocess’
/home/offrance/.gem/ruby/1.9.1/gems/actionmailer-3.2.21/lib/action_mailer/base.rb:453:in initialize' /home/offrance/.gem/ruby/1.9.1/gems/actionmailer-3.2.21/lib/action_mailer/base.rb:439:innew’
/home/offrance/.gem/ruby/1.9.1/gems/actionmailer-3.2.21/lib/action_mailer/base.rb:439:in method_missing' /home/offrance/.gem/ruby/1.9.1/gems/devise-2.2.8/lib/devise/models/authenticatable.rb:175:insend_devise_notification’
/home/offrance/.gem/ruby/1.9.1/gems/devise-2.2.8/lib/devise/models/confirmable.rb:99:in send_confirmation_instructions' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/performable_method.rb:30:inperform’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/backend/base.rb:94:in block in invoke_job' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:incall’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in block in initialize' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:incall’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in execute' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:40:inrun_callbacks’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/backend/base.rb:91:in invoke_job' (eval):3:inblock in invoke_job_with_newrelic_transaction_trace’
/home/offrance/.gem/ruby/1.9.1/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:352:in perform_action_with_newrelic_trace' (eval):2:ininvoke_job_with_newrelic_transaction_trace’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/worker.rb:199:in block (2 levels) in run' /home/offrance/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/timeout.rb:68:intimeout’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/worker.rb:199:in block in run' /home/offrance/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/benchmark.rb:295:inrealtime’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/worker.rb:198:in run' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/worker.rb:275:inblock in reserve_and_run_one_job’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in call' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:inblock in initialize’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in call' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:inexecute’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:40:in run_callbacks' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/worker.rb:275:inreserve_and_run_one_job’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/worker.rb:182:in block in work_off' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/worker.rb:181:intimes’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/worker.rb:181:in work_off' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/worker.rb:146:inblock (4 levels) in start’
/home/offrance/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/benchmark.rb:295:in realtime' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/worker.rb:145:inblock (3 levels) in start’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in call' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:inblock in initialize’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in call' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:inexecute’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:40:in run_callbacks' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/worker.rb:144:inblock (2 levels) in start’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/worker.rb:143:in loop' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/worker.rb:143:inblock in start’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/plugins/clear_locks.rb:7:in call' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/plugins/clear_locks.rb:7:inblock (2 levels) in class:ClearLocks
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:79:in call' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:79:inblock (2 levels) in add’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in call' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:inblock in initialize’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:79:in call' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:79:inblock in add’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in call' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:inexecute’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:40:in run_callbacks' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/worker.rb:142:instart’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/command.rb:124:in run' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/command.rb:112:inblock in run_process’
/home/offrance/.gem/ruby/1.9.1/gems/daemons-1.2.2/lib/daemons/application.rb:265:in call' /home/offrance/.gem/ruby/1.9.1/gems/daemons-1.2.2/lib/daemons/application.rb:265:inblock in start_proc’
/home/offrance/.gem/ruby/1.9.1/gems/daemons-1.2.2/lib/daemons/daemonize.rb:84:in call' /home/offrance/.gem/ruby/1.9.1/gems/daemons-1.2.2/lib/daemons/daemonize.rb:84:incall_as_daemon’
/home/offrance/.gem/ruby/1.9.1/gems/daemons-1.2.2/lib/daemons/application.rb:269:in start_proc' /home/offrance/.gem/ruby/1.9.1/gems/daemons-1.2.2/lib/daemons/application.rb:295:instart’
/home/offrance/.gem/ruby/1.9.1/gems/daemons-1.2.2/lib/daemons/controller.rb:56:in run' /home/offrance/.gem/ruby/1.9.1/gems/daemons-1.2.2/lib/daemons.rb:193:inblock in run_proc’
/home/offrance/.gem/ruby/1.9.1/gems/daemons-1.2.2/lib/daemons/cmdline.rb:88:in call' /home/offrance/.gem/ruby/1.9.1/gems/daemons-1.2.2/lib/daemons/cmdline.rb:88:incatch_exceptions’
/home/offrance/.gem/ruby/1.9.1/gems/daemons-1.2.2/lib/daemons.rb:192:in run_proc' /home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/command.rb:110:inrun_process’
/home/offrance/.gem/ruby/1.9.1/gems/delayed_job-4.0.4/lib/delayed/command.rb:86:in daemonize' /home/offrance/apps/openfoodnetwork/current/script/delayed_job:5:in'`

Just to confirm, my server is staging and mail method is staging, too.

The last update ?

It finally works. Apperently, the environment variabale RAILS_ENV needs to be setup to the environment type (in my case staging) for delayed_job to work properly.

So, export RAILS_ENV="staging" in .profile and launch sudo service monit start to have delayed_job work using the proper Mail Method config.

So, for me, the issue is closed.

2 Likes

Hooray! Nice work chasing that one down.

Hi Rohan,

One question, how should me document that in a convinient place for new platform setters ? What would you suggest ?

@marito59 Would be amazing if you could improve the notes here https://github.com/openfoodfoundation/ofn_deployment/wiki.