Not receiving mail from Heroku Sendgrid addon - ruby-on-rails

So i've look at a few similar posts here on SO, but for some reason my sendgrid config in heroku is not working.
Here's my config / production.rb
config.action_mailer.default_url_options = { :host => 'poliking.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
ActionMailer::Base.smtp_settings = {
:from => 'wesleycreations#gmail.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'poliking.herokuapp.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
Everything worked perfectly fine in development. I tried all the obvious, YES variables are properly set and YES I enabled my gmail to allow mail from less secure apps.
added gem sendgrid gem to my gem file
gemfile.rb
gem 'sendgrid-ruby'
Again, everything working fine in development and I am receiving email to same email address. But this isn't working in production. Any thoughts?
Here's the log:
...MailForm::Notifier#contact: processed outbound mail in 3.3ms...
Delivered mail 5f246d3cbf2d9_42af68b690f1c810d6#dad81cb4-1ce9-440e-b8...

With config.action_mailer.raise_delivery_errors = false, the errors raised during e-mail delivery will be suppressed.
Therefore, change that option to true so that you can diagnose the problem.

Related

Why can't I see any emails in my inbox sent from my Heroku Rails app using SendGrid SMTP Relay in development mode?

I'm trying to switch over to SendGrid from Mandrill in my Rails 4.2 app through SendGrid's SMTP Relay. I have set the 'To Email' to be my personal email address so that I can view the emails that have been sent, however none of the emails actually appear in my inbox despite the rails console claiming to have processed and sent the email.
I am fairly certain all my mailers have the appropriate smtp settings as I have mostly followed the instructions provided on the SendGrid website: https://sendgrid.com/docs/Integrate/Frameworks/rubyonrails.html
I have also tested my connectivity to SendGrid's SMTP Relay through telnet and the connection is succesful.
My SendGrid dashboard indicated that 0 emails have been sent. None of my emails appear under the Suppressions tab either so it's not like they have bounced or have been blocked.
This is in my config/environment.rb:
ActionMailer::Base.smtp_settings = {
:user_name => 'apikey',
:password => ENV['SENDGRID_API_KEY'],
:domain => 'heroku.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
This is in my config/environments/development.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => 'smtp.sendgrid.net' }
This is the line in my controller that calls my ApplicationMailer:
ApplicationMailer.send_email(user, 'mypersonalemail#email.com', 'Test Subject').deliver
And this is what gets printed in the console when the mailer method is executed:
ApplicationMailer#send_email: processed outbound mail in 789.9ms
Sent mail to mypersonalemail#email.com (103.4ms)
But I still don't get any emails in my inbox or spam folder. Does anyone know how I can solve this? Thanks in advance.
Your domain and host options are wrong. Use localhost:3000 (unless you're using docker or something at which point replace localhost:3000 with 0.0.0.0:8000)
#/environments/development.rb
#Mailer Options
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'localhost:3000',
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = { host: 'http://localhost:3000' }
config.action_mailer.asset_host = 'http://localhost:3000'
Make sure to add the sendgrid credentials to your local machine as environment vars. To get them, go to your heroku app and click on settings, then "reveal config vars". Then add those sendgrid credentials to your local machine as env. vars and you're done.

Action Mailer production.rb not working when deployed via Sendgrid and Heroku

I'm currently in the process of trying to send Account Confirmation emails to any new user that creates an account on my Rails app.
I've successfully deployed locally via development.rb, but for some reason I get an error message every time "We're sorry, but something went wrong. If you are the application owner check the logs for more information". I've reviewed several resources both here on Stack Overflow as well as Heroku, Youtube and have not been able to find a solution.
Here is my code in environments/production.rb:
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.sendgrid.net",
port: 587,
domain: ENV["SENDGRID_DOMAIN"],
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["SENDGRID_USERNAME"],
password: ENV["SENDGRID_PASSWORD"]
}
config.action_mailer.default_url_options = {:host => "<myherokuappname>.herokuapp.com/"}
config.action_mailer.perform_caching = false
Again just to confirm, I am able to deploy emails locally, just not at the production level. Any tips would be greatly appreciated.
I recently integrated SendGrid into my Heroku app too. My production.rb settings are as follows:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { host: '<myherokuappname>.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => '<myherokuappname>.herokuapp.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
I tested this out just a few minutes ago and it sends fine.

Completed 500 Internal Server Error in Rails 4 Devise Signup process

When I go to signup a new user on the site I fill in the form, click submit, and it sits there for a few seconds, then dispays 'We're sorry, but something went wrong.'
The Log is below...
https://gist.github.com/th3cuda/225f1352a7cfeee3f8f8
This is deployed on digitalocean.
production.rb
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
config.action_mailer.default_url_options = { :host => 'MY_HOST' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.MY_DOMAIN.com',
:port => 465,
:domain => 'MY_DOMAIN',
:user_name => 'MY_EMAIL',
:password => 'PASSWORD',
:authentication => 'plain',
:enable_starttls_auto => true
}
end
Since it's taking a while, it could be looking for sendmail (it uses /usr/sbin/sendmail by default) to send the email.
I would make sure that it's in place, that it can be used by the app, and that the config/(Dev, Prod, etc.) allows it to deliver email.
Is any of that helpful? Let me know what you find so I can give a better answer.
Sorry to add another answer, but formatting here is important.
config.action_mailer.default_url_options = { :host => 'MY_HOST' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtpout.secureserver.net',
:port => 80,
:domain => 'www.example.com',
:user_name => 'johndoe#example.com',
:password => 'yourpassword',
:authentication => 'plain'
}
end
Notice I removed the starttls option, and set port to 80. Obviously, replace with your real values. If you're using constants, please avoid using those until this gets resolved.

Email for user confirmation not sending in production. Rails, Heroku, Devise, Gmail

I've looked all over Google and stackoverflow for an answer, but none of them work.
I'm trying to set up smtp emailing for user confirmation after signing up. It works fine in development. Even with MailCatcher on, it bypasses it somehow and sends to the right email from my assigned gmail.
Here's what's in development.rb:
config.action_mailer.default_url_options = { :host => 'localhost:3000'}
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {:address => "localhost", :port => 1025}
Here's what's in production.rb:
config.action_mailer.default_url_options = {:host => 'myapp.herokuapp.com', :protocol => 'http'} #I've also tried it without ":protocol => 'http'"
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:authentication => :plain, # I've also tried :login
:enable_starttls_auto => true, # Also tried tls => true
:user_name => 'myemail#gmail.com',
:password => 'mypassword'
} #I've also tried having the attribute :domain => 'myapp.herokuapp.com',
In config/initializers/devise.rb
config.mailer_sender = 'please-change-me-at-config-initializers-devise#example.com' #It still sends from myemail#gmail.com even with this line uncommented.
I don't know how to paste out my entire 7 pages (in word document) worth of heroku logs in code block, so I've pasted them in a google doc.
google doc of heroku logs (I believe I highlighted the part where it started to go wrong on page 1-2):
https://docs.google.com/document/d/1G-cCX7T1sPL5XtjyjHRaWmzfaBbWkuTR2edsDmDm1Pc/edit?usp=sharing
I'm not sure where it's finding the correct email to send from in development. I'm still a novice at this.
edit: I just found out that users that were registered before adding confirmation are not able to log in as well, so it might be a users problem with heroku. But everything still works fine in development.
Help is greatly appreciated, thanks!
You might miss this config.action_mailer.perform_deliveries = true
Please check if your gmail asked for captcha for sending the mail or not. and to debug the error please make config.action_mailer.raise_delivery_errors = true on your production.rb .Please check the similar question Net::SMTPAuthenticationError when sending email from Rails app (on staging environment)

emails not sending in ruby on rails

I did the same thing as in this link http://www.tutorialspoint.com/ruby-on-rails/rails-send-email.htm. it is showing mail sent in output window of net-beans with the message but it is not actually sending the mail. can anyone tell me what could be the problem?
i have searched a lot but m not getting any solution.
I am using net-beans with ruby 1.5.1, rails 2.3.8. I have searched but I only got the solution to update j-ruby. If it is so then please tell me how to use updated version of j-ruby in net-beans.
the following code is in environment.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail',
:user_name => "id#gmail.com",
:password => "",
:authentication => 'plain',
:enable_starttls_auto => true }
thanks
can you please check that whether you have do this or not
config.action_mailer.perform_deliveries = true
Please let me know
Thanks
Please check with your network provider if your smtp port is open. or check using telnet commands. If you work under a company network which has restrictions on sending mails, you should explicitly ask for permission and get the port opened.
The mail sent message will be shown in output even if it isnt actually sent. So pls make sure you have the following changes made to know the errors in your config/environments/development.rb or production.rb depending on in which mode you are running your server
config.action_mailer.raise_delivery_errors = true
Visit the following link for more detail about Action Mailer.
Update your mailer settings:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail',
:user_name => "id#gmail.com",
:password => "******",
:authentication => 'plain',
:enable_starttls_auto => true }
Where ****** is your email password.

Resources