So I want devise to utilize amazon ses to send the "I forgot my password" emails to a user. I have followed all of the steps for setting up devise with Gmail and then tried to configure SES as the mailer in production.rb I am new with ruby and I am sure there is something I have done incorrectly with either my syntax or configuration.
Production.rb
config.action_mailer.delivery_method = :smtp,
config.action_mailer.smtp_settings = {
:address => "email-smtp.us-west-2.amazonaws.com",
:user_name => ENV['AWS_SMTP_USER'], # Your SMTP user here.
:password => ENV['AWS_SMTP_PASSWORD'], # Your SMTP password here.
:authentication => :login,
:enable_starttls_auto => true
}
I stored both AWS_SMTP_USER & AWS_SMTP_PASSWORD to the config using "$ Heroku Config"
Devise.rb
config.mailer_sender = 'Admin#synapticecho.com'
I don't think I am missing anything else, but I haven't found anyone trying to use Devise & SES as the mailer. I'm just not sure what other pieces I might be missing and I didn't find the AWS documentation all that helpful for configuring SES to work with Devise.
I can post the github project if it helps.
In my case.
I got the following error.
Net::SMTPFatalError (554 Message rejected: Email address is not verified
but, just like you. I didn't know missing anything else.
try below setting.
config.action_mailer.default_url_options = { host: Rails.application.secrets.HOST }
config.after_initialize do
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: Rails.application.secrets.ACTION_MAILER_ADDRESS,
port: Rails.application.secrets.ACTION_MAILER_PORT,
domain: Rails.application.secrets.ACTION_MAILER_DOMAIN,
user_name: Rails.application.secrets.ACTION_MAILER_USER_NAME,
password: Rails.application.secrets.ACTION_MAILER_PASSWORD,
authentication: :login,
ssl: true,
tls: true,
enable_starttls_auto: true
}
end
It works, my env.
That point is config.after_initialize.
but, I don't know why need it.
Rails 4.1.4
Devise 3.2.4
AWS SES
In AWS EC2
Verified email's domain is 'gmail.com' ( I'll change it)
I fix the problem by adding the following line in production.rb.
ActionMailer::Base.default :from => 'my.verified.email.address'
Related
I am trying to setup action_mailer with Rails 4.1.0 to send emails.
In my config/environments/{env}.rb, I have:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.mandrillapp.com',
port: 587,
domain: 'domain.com',
authentication: 'login',
user_name: 'email#domain.com',
password: 'pass',
enable_starttls_auto: true }
It's working fine in development, but in prod it's trying to connect to localhost.
m = Mail.new
m.delivery_method
=> #<Mail::SMTP:0xbd79fdac #settings={:address=>"localhost", :port=>25, :domain=>"localhost.localdomain", :user_name=>nil, :password=>nil, :authentication=>nil, :enable_starttls_auto=>true, :openssl_verify_mode=>nil, :ssl=>nil, :tls=>nil}>
But when I do "puts Rails.application.config.action_mailer" Im getting the correct config
{:raise_delivery_errors=>false, :default_url_options=>{:host=>"domain.com"}, :delivery_method=>:smtp, :smtp_settings=>{:address=>"smtp.mandrillapp.com", :port=>587, :domain=>"domain.com", :authentication=>"login", :user_name=>"email#domain.com", :password=>"password", :enable_starttls_auto=>true}, :assets_dir=>"xxx", :javascripts_dir=>"xxx", :stylesheets_dir=>"xxx", :asset_host=>nil, :relative_url_root=>nil}
Any idea?
The Mail gem won't use your ActionMailer config by default. ActionMailer uses Mail but those configuration settings will only apply if you send mail via ActionMailer.
If it's working in your dev mode, then you certainly have configured the Mail gem separately in your development.rb environment file, or in an environment specific initializer.
I forgot I had this config in my development.rb
Mail.defaults do
delivery_method Rails.configuration.action_mailer.delivery_method, Rails.configuration.action_mailer.smtp_settings
end
You need to add the host option for the default_url_options hash on the production.rb file, like so:
config.action_mailer.default_url_options = { :host => ENV['HOST_DEFAULT_URL'],
only_path: false }
That should do the trick.
I am working on my first rails application and I have just pushed it to production through Heroku. The next step in my assignment is to create an account in production and have it send an email confirmation to that email.
config/environments/production.rb
config.action_mailer.default_url_options = { host: 'alex-bloccit.herokuapp.com' }
config/initializers/setup_mail.rb
if Rails.env.development?
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: 'smtp.sendgrid.net',
port: '587',
authentication: :plain,
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
domain: 'heroku.com',
enable_starttls_auto: true
}
end
config/initializers/setup_mail.rb
if Rails.env.development? || Rails.env.production?
config/initializers/devise.rb
config.mailer_sender = "alex.colbert1987#gmail.com"
The code updates to github and pushes to Heroku just fine, but when I go to the website and I attempt to create an email under the email. Hope this provides enough information to troubleshoot.
In config/initializers/setup_mail.rb, you have if Rails.env.development? before the ActionMailer configuration. This config won't be run in production because of the way the if statement is structured.
I am getting this error whilst trying to send emails through gmail -
Net::SMTPAuthenticationError (530 5.7.0 Must issue a STARTTLS command first. pw17sm4922458lab.5
):
app/controllers/contact_controller.rb:11:in `create'
I have tried loads of different things but to no avail, below is my settings from production.rb
# Change mail delvery to either :smtp, :sendmail, :file, :test
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "bizmodev.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: '******.*****#gmail.com',
password: '********'
}
# Specify what domain to use for mailer URLs
config.action_mailer.default_url_options = {host: "bizmo.co.uk"}
Any help on this matter would really be appreciated.
OK fixed it, basically I installed sendmail on my VPS and then restarted Apache and it now works -
Ubuntu Sendmail command line install
apt-get install sendmail
Hope this may help someone in the future...
you can enable starttls like this:
config.action_mailer.smtp_settings = {
....
:enable_starttls_auto => true}
I need to use a mailer for sending out emails to users to set their passwords to the "recoverable" function of Devise and active admin. On the development environment I have done this by adding the following to these files:
config/environments/development
#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 => 'XXXXX#gmail.com',
:password => 'XXXXXXX'
}
How do I get the same functionality for the production environment? I want to deploy my app to Heroku. What files and code would I need to add?
All configurations you have set in Development mode will work EXCEPT you will need to reconfigure the default mailer url.
So.
Copy-paste your settings from development.rb.
Point your default mailer to your heroku app:
config.action_mailer.default_url_options = { :host => 'YOURAPPNAME.herokuapp.com' }
Also, be careful of any email limits your smtp may have when moving to production. It's hard to trigger gmail's smtp limits while developing, for example, but they could be more easily triggered in production.
If it works in development mode, then it will work in production mode.
Supposing everything is setup correctly, resetting a password in development will already send an actual email using your gmail account.
Devise only relies on the mailer config setup correctly (which you have done), and configuring devise to allow password reset, and possibly another setting for the From field of the email.
This should work fine!
As long as config/environments/production.rb has the same thing with an exception. The default_url_options should have a :host value of 'localhost' only in development and 'YOURAPPNAME.herokuapp.com' in heroku production.
i.e.
config.action_mailer.default_url_options = { :host => 'YOURAPPNAME.herokuapp.com' }
Remember to unlock captcha on gmail, otherwise it won't send email from heroku (unknown source). You can do that by going to this link: http://www.google.com/accounts/DisplayUnlockCaptcha
Just as a suggestion, I'd say move this from environments.rb
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
and place is in environments/development.rb as
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
It's not needed in production.
See Net::SMTPAuthenticationError when sending email from Rails app (on staging environment) for more information in regards to gmail seeing heroku as an unknown host.
im having a problem getting sendgrid to send emails successfully on a rails 3.1 app that's using authlogic for authentication and is being deployed on heroku. i have the following action mailer configuration on config/environments/[development.rb and production.rb]:
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.default_charset = "utf-8"
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => 587,
:domain => ENV['SENDGRID_DOMAIN'],
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => 'plain',
:enable_starttls_auto => true
}
for production.rb, the above code is the same except for
config.action_mailer.default_url_options = { :host => [app name in heroku] }
when i run it development mode, i get the following error reported:
Completed 500 Internal Server Error in 21740ms
Net::SMTPFatalError (550 Cannot receive from specified address notification#[app-domain]: Unauthenticated senders not allowed
):
i now dont really know how to set it up to get it working. does anyone with some prior experience on setting up sendgrid on heroku and rails know what's going on?
thank you so much. you guys are the best!!!
I spent half a freakin' day on this and finally got mine working now. Quite frustrated as it was due to a poor documentation error. I'm running Rails 3.1 and Cedar stack on Heroku by the way.
So http://devcenter.heroku.com/articles/sendgrid will tell you to put your SMTP settings stuff in config/initializers/mail.rb. BUT... on http://docs.sendgrid.com/documentation/get-started/integrate/examples/rails-example-using-smtp/ it says to put all your SMTP settings stuff in config/environment.rb instead of config/initializers/mail.rb
So the solution is to put that in your environment.rb file. This is how my environment.rb looks:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Freelanceful::Application.initialize!
# Configuration for using SendGrid on Heroku
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:user_name => "yourSendGridusernameyougetfromheroku",
:password => "yourSendGridpasswordyougetfromheroku",
:domain => "staging.freelanceful.com",
:address => "smtp.sendgrid.net",
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
To get your SendGrid username and password, type
$ heroku config -long
Hope that helps.. and more people in the future of this headache.
I'm assuming you mean development mode as in locally? If so, I don't think the SendGrid add-on let you send email from outside the Heroku network (as they have standalone accounts that they would prefer you to use).
Saying that, you don't need to configure mail in production when using the SendGrid add-on as it is automagically configured for you when you deploy your application.
Therefore you can remove your config.action_mailer.smtp_settings code and simply use the default in development.
Also note that if you're running your Heroku app on the Bamboo stack you don't need to configure your settings in the environment.rb file since Heroku does it for you.
However you do need to git push at least once after you activated the app to Heroku to set these settings. I made that mistake this morning and found your post.