Manage registration and sending emails in different environments

In a Rails application, I installed a new intermediate environment with the following options in the environments/ file:

 config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp 

However, when the system generates an email, it is sent to the staging.log file instead of being sent. My SMTP settings work fine in other environments. What configuration am I missing to send emails?

Edit: Yes, the intermediate window is configured correctly for the SMTP server to which it has access. It seems that the problem is not with the SMTP settings (if it were, would I not get errors in the logs?), But with the Rails configuration. The application still redirects emails to the log file (saying "Sent mail: ..."), as opposed to actually going through SMTP.

Edit # 2: It seems that the letters were indeed sent correctly, they just print in the journal. I am trying to use the sanitize_email stone to redirect mail to a different address, and this does not seem to work, so I thought the emails did not go out. Therefore, I think this solves my problem, although I'm still curious that in the settings, ActionMailer controls whether emails are sent, logged in the log file, or both.

Edit # 3: The problem with sanitize_email was that I needed to add a new staging environment in ActionMailer::Base.local_environments . I will leave this question open to find out if anyone can answer my last question (what determines if ActionMailer emails are sent, are they logged in the log file, or both?)

+6
email ruby-on-rails smtp actionmailer
source share
1 answer

As for your third edit, registration is a function from which the log level is set for the application itself, and not any specific setting in ActionMailer .

In Rails 2.3, ActionMailer::Base just send an email to any configured log, if any. The recipient is sent to the info log, and the body of the message is sent to the debug log. (My comments. The rest is straight from the source code.)

 def deliver!(mail = @mail) raise "no mail object available for delivery!" unless mail # # Logging happens first (or not) # unless logger.nil? logger.info "Sent mail to #{Array(recipients).join(', ')}" logger.debug "\n#{mail.encoded}" end # # And then we decide if an email should really get sent # begin __send__("perform_delivery_#{delivery_method}", mail) if perform_deliveries rescue Exception => e # Net::SMTP errors or sendmail pipe errors raise e if raise_delivery_errors end return mail end 

Your environment.rb or staging.rb should have a line that controls the level of the log. Something like the following:

 config.log_level = :debug 

All this is completely separate from the already configured configuration of the mail program, which controls whether the email is sent or not.

 config.action_mailer.perform_deliveries = true 
+10
source share

All Articles