Exception Notification - How to Shut Off in Dev. Mode - ruby-on-rails

I've been happily using exception notification up till now and never sent an email when running in development mode. Now, the gem seems to want to send me an email whenever an exception occurs -- particularly a routing error. Is there some config setting I'm missing? The dox seem to have dried up and blown away.

Assuming you have an initializer to set up your configuration, just wrap it in a conditional to check if it's in production mode:
if Rails.env.production?
Whatever::Application.config.middleware.use ExceptionNotifier,
:email_prefix => "[Whatever] ",
:sender_address => %{"notifier" <notifier#example.com>},
:exception_recipients => %w{exceptions#example.com}
end

Part 1: set up different configurations for ExceptionNotifier in your config/environments/environment_name.rb files. For example, in config/environments/development.rb, use something like this to send your notifications elsewhere, or to a black hole:
YourApp::Application.configure do
<other stuff>
config.middleware.use ExceptionNotifier,
:email_prefix => "[YourApp - DEVELOPMENT:#{`hostname`}] ",
:sender_address => %{"notifier" <notifier##{`hostname`}>},
:exception_recipients => %w{<some_bitbucket_email_address>}
end
This way, your ExceptionNotifier is still configured in all environments. If it isn't configured, any direct calls to
ExceptionNotifier::Notifier.background_exception_notification(e).deliver
will throw exceptions, which could be undesired behavior inside a rescue block.
Part 2: try setting this config parameter:
config.consider_all_requests_local = true
I picked that up from the reverse question to this: Exception notifier plugin not sending emails

Rails 3
Is better write the configuration in the production environment, look at my examle
APP::Application.configure do
...
..
.
config.middleware.use ExceptionNotifier,
:email_prefix => "[Error] ",
:sender_address => %{"Notificacion de error" <notifier#example.com>},
:exception_recipients => %w{addres1#email.com}

Related

EOF error in Rails utilizing the devise gem

I've recently set up the devise gem for authentication and all is working well excluding the forgot my password function. My smtp is currently pointed towards a yahoo email address. Yet, I get a EOF end of file extension error. In development it delivers message just fine ,but to no avail in production. Also, I initialized the ENV variables for username and password with Heroku Config:set .Addtionally, I tried port 587. Any help would be much appreciated! I'm fairly new to rails and searched for similar log issues, but most varied significantly in similarity to this issue. Thank you!
config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = {:host => 'https:app.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = {
:user_name => ENV['example#yahoo.com'],
:password => ENV['examplepass'],
:domain => 'https://example.herokuapp.com/',
:address => 'smtp.mail.yahoo.com',
:port =>465,
:authentication => "plain",
:enable_starttls_auto => true,
}
My first think:
I think your file have non visible characters, try to clean your file. https://alvinalexander.com/blog/post/linux-unix/how-remove-non-printable-ascii-characters-file-unix
Erase the file and create a new one an rewrite the config, avoid the copy paste. maybe works if you do a copy paste without format to note bloc, word something like that and then copy that back to your file.
Also read more What is an EOFError in Ruby file I/O?
https://airbrake.io/blog/ruby-exception-handling/eof-error
Continue searching i found this
EOFError in Devise::PasswordsController#create
Devise mailer EOF error
a user comment this
Ah classic. My config/secrets.yml isn't tracked in git (naturally) and >looks like it was overwritten and lost those entries for the email >provider smtp/username/password at some point. Thanks
Another one Rails EOFError (end of file reached) when saving a devise user
The resolution to my issue was two fold. I didn't have the heroku config vars properly set up and initialized.My .gitignore file didn't have the exclusions as well to prevent uploading to repository. In conclusion, I added the figaro gem, bundle exec install figaro , and it created the application.yml needed to store that actual user/pass information. https://railsapps.github.io/rails-environment-variables.html ----> quite useful in explaining the options for setting the vars.
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:address => 'smtp.sendgrid.net',
:port =>587,
:authentication => :plain,
:enable_starttls_auto => true,
Also in the above code , I didn't have domain specified to heroku.com but my application domain on Heroku. For production.rb you do need the default url set to your applications name. If you kept the default url "heroku.com" in production.rb it would 404 error when the emailed link was clicked on.
config.action_mailer.default_url_options = {:host => 'https://exampleapp.herokuapp.com/' }
Thanks for the help! I also hope this can be of help to other new rails devs.

Using Sidekiq with Mailer to send asynchronous emails [RAILS]

So I am currently trying to use the Rails gem 'sidekiq' to send a large number of emails asynchronously, so it does not bog down the load time for the next page.
Everything I have works except for this:
FeedbackMailer.invite_contact(current_user, current_business, contact).deliver()
This is my own mailer and a set of paramters which it must take to create the email for the client.
The error that gets thrown by sidekiq is this:
Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
The default_url_options[:host] is set in the application.rb, but does not seem to get read here. I also tried setting only_path: true and got the same error still.
I can send emails just find when I am outside one of sidekiq's workers, the problem only exists there. Anyone know of a workaround so that emails can be sent from sidekiq's workers?
Also before you answer, using Mailer.delay doesnt really solve my problem, because there is alot of other code around the mailing that must go off during every iteration of the loop.
This error happens when your mail is not configured properly. Check that you have something like this in the relevant environment file (production.rb or staging.rb)
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.something.com',
:port => 587,
:domain => 'yourdomain.com',
:user_name => 'account-admin#yourdomain.com',
:password => 'your secure password',
:authentication => 'plain',
:enable_starttls_auto => true
}

What causes a End Of File Error when Rails Mailer sends an email?

A Rails 3.2.8 application developed with a gmail account as the "sending address".
When mail sending works my environment.rb file contains this:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:authentication => :login,
:user_name => "accountname",
:password => "123456789"
}
I get this message in my application log:
EOFError (end of file reached):
when the above code is changed to what is shown below:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "mail.company.com",
:port => 25,
:domain => "company.com",
:authentication => :login,
:user_name => "accountname",
:password => "123456789"
}
I can tell you I -am- able to send a manual email message to the email address
and see it arrive when using a email client such as ThunderBird, thus I know
the accountname#company.com is functional.
I don't understand how an end of file error comes into play.
I also cannot figure out how to get more information to appear in the log.
I look forward to reading a few suggestions of determining the cause of the End Of File.
Started POST "/sendInvites?locale=en&lot_id=18&user_id=17" for 99.99.99.99 at 2013-10-03 08:52:09 -0700
Processing by WaitingListsController#sendInvites as HTML
Parameters: {"authenticity_token"=>"uwz/6pW1rLPXR4gU3m3OwCmU0O3DSJ/haNM2/ai+OR8=", "locale"=>"en", "lot_id"=>"18", "user_id"=>"17"}
=======>>>> Beginning Send Invitation Process <<<<=======
=======>>>> just before the PassEmailer.requestApprovedWL IS called to send the invitation <<<<=======
>>>> Beginning ::: requestApprovedWL(user_info) <<<<=======
Rendered pass_emailer/requestApprovedWL.erb (0.9ms)
>>>> at the end of ::: requestApprovedWL(user_info) <<<<=======
Completed 500 Internal Server Error in 1718ms
EOFError (end of file reached):
app/controllers/waiting_lists_controller.rb:276:in `sendInvites'
For anyone still experiencing this issue, Whenever appears to default to Production. It is using your Production variables (or looking for them) while in your Development or Staging. Also, per the docs it does not load the Rails environment.
While you are in development or staging you must manually let schedule.rb know this. After finding the File.expand_path method here, the following is how I start my schedule.rb file:
require File.expand_path(File.dirname(__FILE__) + "/environment")
set :environment, Rails.env
set :output, Rails.root.join('log','cron.log')
This provides you the Rails environment and allows you to also set the path for logging.

Chaining Webrick Proxies

I have been trying to test the chaining of Webrick proxies, and I am having some trouble.
Each proxy works fine on its own from 127.0.0.1:port (when :ProxyURI is commented out for proxy_2), but I am getting the error:
ERROR unsupported method `GET'.
from proxy_2 output (httpproxy.rb) when I try chaining them.
To clarify, when I chain them I am using 127.0.0.1:8086 as my access point from another application.
Looking at the logs for proxy_1, it appears that it is not receiving any requests.
Any help would be much appreciated.
require 'webrick'
require 'webrick/httpproxy'
port_1 = 8085
port_2 = 8086
proxy_1 =
WEBrick::HTTPProxyServer.new(
:Port => port_1,
:ServerType => Thread,
:Logger => WEBrick::Log.new("./logs/#{port_1}.out"),
:ServerName => "future_authentication_proxy"
)
proxy_1.start
proxy_2 =
WEBrick::HTTPProxyServer.new(
:Port => port_2,
:ProxyURI => '127.0.0.1:'+port_1.to_s
)
trap("INT"){
proxy_1.shutdown
proxy_2.shutdown
}
proxy_2.start
You passed wrong ProxyURI option, it should be something like:
:ProxyURI => URI.parse("http://#{host_1_ip}:#{port_1}/")

Rails 3: SMTP Settings for Google Apps / Heroku

Here are my smtp settings for Google Apps in setup_mail.rb.
:address => "smtp.gmail.com",
:port => 587,
:domain => 'mysite.co',
:user_name => 'noreply#mysite.co',
:password => 'password',
:authentication => 'plain',
:enable_starttls_auto => true
My development logs show in detail the e-mails being generated and sent to the right e-mail address... but they are not arriving. I can only think that there must be something wrong with the settings above. Can you see what the problem is?
Once this is solved, would I have any issue getting it to work on Heroku?
Note: the above is logging a deprecation warning:
DEPRECATION WARNING: Giving a hash to body is deprecated, please use instance va
riables instead. (called from process at C:/Sanj/Ruby192/lib/ruby/gems/1.9.1/gem
s/actionmailer-3.0.0/lib/action_mailer/old_api.rb:77)
I think if you are using rails 3, the correct approach to setup mail would be to follow this railscasts tutorial on action mailer.
in your user controller don't forget to add the .deliver
UserMailer.registration_confirmation(#user).deliver
that is what stumped me
Turned out that the issue was elsewhere - an old AuthLogic tutorial had put me in the right direction on sending out activation codes but the wrong direction on sending out the e-mails themselves. Rails was generating the e-mail but not sending it because the mail_helper's code wasn't going the final step.
If you're reading this in retrospect, what I learned: make sure your Rails 3.0 user_mailer has (or similar):
mail(:to => "#{user.login} <#{user.email}>", :subject => "Registered" )
I haven't used rails3 but I remember reading that sent emails in development are sent to the sender. Your deprecation warning is because you're defining variables for the email template in the previous hash format. Rails 3 works differently. In my experience deploying to heroku works flawlessly but you will need to define mx records.

Resources