I've got a Ruby on Rails app hosted with Heroku.
I'm using Devise for User Authentication. Trying to get Mandrill to send the Devise confirmation email.
I'm getting the following error in my heroku logs
Sent mail to EXAMPLE#gmail.com (23.4ms)
2015-02-04T00:38:02.334898+00:00 app[web.1]: Completed 500 Internal Server Error in 335ms
Note: the email is not being received by EXAMPLE#gmail.com.
Here's the code for Mandrill in my config/environments/production.rb
config.action_mailer.default_url_options = { :host => "example.herokuapp.com" }
config.action_mailer.smtp_settings = {
:port => '587',
:address => 'smtp.mandrillapp.com',
:enable_starttls_auto => true,
:user_name => ENV['EXAMPLE#heroku.com'],
:password => ENV['EXAMPLE'],
:authentication => 'login',
:domain => 'example.herokuapp.com'
}
EXAMPLE in the code above is actually replaced by my account information.
What am I missing?
I ended up switching to SendGrid as a Heroku AddOn and it solved my problem.
Here's the code that ended up working for me in config/environments/production.rb:
config.action_mailer.default_url_options = { :host => "http://www.EXAMPLE.com" }
config.action_mailer.smtp_settings = {
:user_name => 'EXAMPLE',
:password => 'EXAMPLE',
:domain => 'EXAMPLE.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
Related
I'm having problems with an error when trying to send mails with my App with Mandrill.
I've seen a lot of people have this problem, and I'm sure it has to do with my mailer configuration. See if someone knows how to deal with this, because I'm desperate about it.
ERROR:
Errno::ECONNREFUSED (Connection refused - connect(2)):
production.rb
# Config default action mailer
config.action_mailer.default_url_options = { :host => "localhost" }
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 587,
:enable_starttls_auto => true,
:user_name => ENV["MANDRILL_USERNAME"],
:password => ENV["MANDRILL_PASSWORD"],
:authentication => 'login',
:domain => 'heroku.com'
}
# Setup for production - deliveries, no errors raised
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default :charset => "utf-8"
We use Mandrill in production like this:
#config/environments/production.rb
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => "587",
:authentication => :plain,
:user_name => "username",
:password => "API key",
:enable_starttls_auto => true
}
We literally have no other options for Heroku - I think you should remove the default_url_options and domain options
I am trying to use the gem Active Admin to send emails to users that I sign up so that they can create a password.
This entails a process of inserting the following code on the config/environments/development.rb
#Added per active admin install instructions
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
#These settings are for the sending out email for active admin and consequently the devise mailer
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.smtp_settings =
{
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com', #you can also use google.com
:authentication => :plain,
:user_name => 'XXX#gmail.com',
:password => 'XXXX'
}
THis works no problems
For deploying to the production site on Heroku. I inserted the following code into the config/environments/production.rb
#Added per active admin install instructions
config.action_mailer.default_url_options = { :host => 'http://XXXX.herokuapp.com/' }
#These settings are for the sending out email for active admin and consequently the devise mailer
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.smtp_settings =
{
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com', #you can also use google.com
:authentication => :plain,
:user_name => 'XXX#gmail.com',
:password => 'XXX'
}
But now the emails donot get sent. Instead I see a "We're sorry soemthing went wrong" message in the browser and the logs say the following lines
2012-08-17T17:39:34+00:00 app[web.1]: cache: [GET /admin/admin_users/new] miss
2012-08-17T17:39:34+00:00 app[web.1]: Started POST "/admin/admin_users" for 96.49.201.234 at 2012-08-17 17:39:34 +0000
2012-08-17T17:39:35+00:00 app[web.1]: Net::SMTPAuthenticationError (535-5.7.1 Please log in with your web browser and then try again. Learn more at
2012-08-17T17:39:35+00:00 app[web.1]: ):
2012-08-17T17:39:35+00:00 app[web.1]: app/models/admin_user.rb:35:in `block in <class:AdminUser>'
2012-08-17T17:39:35+00:00 app[web.1]: cache: [POST /admin/admin_users] invalidate, pass
Where should I go from here? Can someone please give me a hand
Here is a useful help from Gmail: http://support.google.com/mail/bin/answer.py?hl=en&answer=14257&p=client_login.
The problem is Gmail prevents suspicious sign-in attempt that may be robot. We need to grant permission to the app so that it can use Google Account to send email.
Gmail requires SSL connections to their mail servers. Try adding this to your SMTP settings:
:enable_starttls_auto => true
Try following code:
ActionMailer::Base.smtp_settings =
{
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com', #you can also use google.com
:authentication => 'plain',
:user_name => 'XXX#gmail.com',
:password => 'XXX',
:enable_starttls_auto => true
}
Changes made:
1. :authentication => :action to :authentication => 'plain'
2. added :enable_starttls_auto => true , as commented by janders223 above.
http://www.google.com/accounts/DisplayUnlockCaptcha click on this and give access to it. The next time it will work
I want to send emails from my rails application on Heroku.
As Heroku doesn't support SMTP, I use external SMTP server.
config/environments/production.rb has the following lines.
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => 'mydomain.com',
:port => 587,
:user_name => "myusername",
:password => "password",
:authentication => :plain,
:enable_starttls_auto => true,
:openssl_verify_mode => 'none'
}
When I send an email from "heroku run console", it works fine. But it doesn't send email from the website. Strangely, "heroku logs --tail" shows "Sent mail to ...". Actually the email is not delivered.
Does anyone have any idea about this issue?
Thanks.
Sam Kong
Have you tried this in config/enviornment.rb
ActionMailer::Base.smtp_settings = {
:address => 'mydomain.com',
:port => 587,
:user_name => "myusername",
:password => "password",
:authentication => :plain,
:enable_starttls_auto => true,
:openssl_verify_mode => 'none'
}
Your configuration is correct. But you have to put it in the correct environment file. In case of Heroku deployment, it should be 'production'. Console works because it uses 'development' as the environment. So put the following code in config/environment/production.rb
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => 'mydomain.com',
:port => 587,
:user_name => "myusername",
:password => "password",
:authentication => :plain,
:enable_starttls_auto => true,
:openssl_verify_mode => 'none'
}
Hope it solves your problem.
If it shows as mail as being sent that I would suggest that it's a config issue at your mail server perhaps preventing relay from the Heroku IP range - it's most odd though if it works through the heroku console and not through your application.
Have you thought of trying the SendGrid Heroku addon just to alleviate any issues with your own mailer server?
I tried to configure actionmailer to send via google apps with smtp.
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "mydomain.com",
:user_name => "username",
:password => "password",
:authentication => 'plain',
:enable_starttls_auto => true }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
However whenever gitlab tries to send an e-mail:
Sent mail to user#my.domain.com (10ms)
Completed 500 Internal Server Error in 29ms
535-5.7.1 Username and Password not accepted
Server runs ruby 1.9.3p194. Why doesn't google apps accept the username/password?
It works now, I think the problem was with the username. it needs the domain in the username. i.e. the problem was
user_name: 'username'
Whereas the correct way (at least for google apps) is
user_name : 'username#mydomain.com'
this works for me:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "you#gmail.com",
:password => "password",
:authentication => 'plain',
:enable_starttls_auto => true }
Try setting the domain to gmail.com
I'm using sendgrid on heroku to send email in production, but would like to send email locally on my mac.
I've configured my development.rb a million different ways and keep getting
"Net::SMTPFatalError: 550 Cannot receive from specified address : Unauthenticated senders not allowed"
Spefically, I tried
varying authentication b/w :plain and :login,
tried using my gmail account credentials,
tried using my google app account credentials.
Nothing seems to work, thoughts?
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
:address => 'smtp.gmail.com',
:domain => 'somedomain.com',
:port => 587,
:user_name => 'username#somedomain.com',
:password => 'somepassword',
:authentication => :plain,
:enable_starttls_auto => true
}
I thought I had set the in the production settings (production.rb), it turns out I had set them in environment.rb. Removed it there and everything started working.
I had set the mail settings by accident in the Environment.rb so it was overriding anything I was doing at the production/development config level.
Could you try this?
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "email#gmail.com",
:password => "password",
:authentication => "plain",
:enable_starttls_auto => true
}