I can't get my Rails app to send emails using Gmail. I can send emails on my local development environment but I can't send it from Heroku.
This is my config file.
application.rb
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:domain => 'gmail',
:port => 587,
:user_name => ENV['GMAIL_USERNAME'],
:password => ENV['GMAIL_PASSWORD'],
:authentication => 'login',
:enable_starttls_auto => true
}
I have tried authentication: 'login' and 'plain' but that didn't work either. I have tried putting this config both into application.rb and production.rb and that didn't work. I've tried domain: "my_my_name_on_heroku.com" but that didn't work either. I have also tried 'mail.google.com' but no luck either.
I have setup environment variables on Heroku with username and password properly (100% sure).
I have enabled less secure apps to get the application working at https://myaccount.google.com/lesssecureapps. No 2-factor authentication. I have enabled captcha to allow to login from different devices at http://www.google.com/accounts/DisplayUnlockCaptcha and still no emails are sent.
On Heroku logs I see that it says "Sending email to...", it renders the template fine, no errors whatsoever but I don't receive any emails. I've checked Spam folder as well but no emails there.
production.rb
config.action_mailer.default_url_options = { host: 'my_app.herokuapp.com' }
config.action_mailer.perform_caching = false
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
What am I missing?
This is an active app I have had forever where the mail still works. Try changing the auth type to a symbol rather than a string. So :plain instead of 'plain'.
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => 'smtp.gmail.com',
:port => 587,
:authentication => :plain,
:domain => 'blarg.com',
:user_name => 'info#blarge.com',
:password => 'password'
}
config.action_mailer.default_url_options = { :host => 'blarg.heroku.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
Related
I am trying to send mails with SendGrid from my Rails app (using Hartl's tutorial). It didn't work by simply using the addon at Heroku because it needed my credit card. Then I signed up on SendGrid and used my credentials as above, but still no mail. Here above is my production.rb file. Some help, please?
config.action_mailer.delivery_method = :smtp
host = '<https://nameless-sierra-13544>.herokuapp.com'
config.action_mailer.default_url_options = { host: host }
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['myusername'],
:password => ENV['mypass#'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
Merci,
In line with the comment above, I believe your values are just a little off. I also believe you need to have a from address set. This is a copy of what I use in production, with your values put in, and it works so hopefully this helps. I do believe that missing a valid from address and the characters in your domain value are why this is not working. Of course, also make sure you have the ENV variables set on heroku.
production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host:'https://nameless-sierra-13544.herokuapp.com' }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
ActionMailer::Base.smtp_settings = {
:from => 'your_email_here#email.com',
:user_name => ENV['myusername'],
:password => ENV['mypass#'],
:domain => 'https://nameless-sierra-13544.herokuapp.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
I use devise and this error occurs when devise try to send email to confirm user's email.
Follow below my development.rb which
development.rb
# Email
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host: 'domain.com' }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.asset_host = 'badoda.com'
config.action_mailer.smtp_settings = {
:address => 'outlook.office365.com',
:port => 587,
:user_name => 'it#domain.com',
:password => 'password',
:domain => 'domain.com',
:authentication => :login,
:enable_starttls_auto => true
}
It seems to be an issue with Office 365 SMTP relay configuration. Please follow the steps here to configure SMTP properly.
Does your MIME message specify the right Sender header?
Net::SMTPAuthenticationError in Devise::ConfirmationsController#create
530-5.5.1 Authentication Required. Learn more at
I am using the gem 'devise'.
to send confirmation email with gmail account.
but, the error in title occur.
I searched many cases similar to my case and tried solutions in there, but those perfectly not worked, so I think my error has some different origin
( what I tried is : 1. less securing myaccount.google.com/u/1/security 2. http://www.google.com/accounts/DisplayUnlockCaptcha)
development.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
:authentication => :plain,
:address => "smtp.gmail.com",
:port => 587,
:domain => "mail.google.com",
:user_name => ENV["******#gmail.com"],
:password => ENV["******"],
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = {:host => 'localhost:3000'}
top most error line in error page
def check_response(res)
unless res.success?
raise res.exception_class, res.message
end
end
please help me... TT
the problem your gmail setting, you should remove the ENV as you put string directly to it (as my understanding this is your local development this will generate an error since you also put config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
:authentication => :plain,
:address => "smtp.gmail.com",
:port => 587,
:domain => "mail.google.com",
:user_name => "******#gmail.com",
:password => "******",
:enable_starttls_auto => true
}
I want to integrate SendGrid in my app and test how things work locally so I have my code send an email on a new user registration. I have my controller calling Notifier.welcome_email(user).deliver
When I tail the logs, the only related thing I see is:
Rendered notifier/welcome_email.html.erb (1.3ms)
But no email gets sent. In my environments/development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => '<user-name-is-here-actually.',
:password => '<and-the-password>',
:domain => 'domain.com',
:enable_starttls_auto => true
}
I still see nothing come through. Can anyone help me get this working locally?
The solution was just to make sure to call 'deliver' on the Notifier method.
I have an app , it uses devise to send confirmation mails for the newly registered users , I have smtp settings under the development.rb file as
config.action_mailer.default_url_options = { :host => 'http://localhost:3000' }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:authentication => :login,
:user_name => "my_username#gmail.com",
:password => "mygmail password"
}
This is throwing me with an error like ,
Net::SMTPAuthenticationError in Devise::RegistrationsController#create
535-5.7.1 Please log in with your web browser and then try again. Learn more at
Any Ideas how to resolve this ?
Resolved using these settings ..
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.perform_deliveries = true
config.action_mailer.default :charset => "utf-8"
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "my_username#gmail.com",
:password => 'my_gmail password',
:authentication => "plain",
:enable_starttls_auto => true
}
I was unuable to resolve this problem with any code. After a while i logged in to gmail account and this is, what it gave me after.
We've detected suspicious activity on your Google Account. Please create a new password to continue using your account.
Read some tips on creating a secure password.
So solution to this problem is simply log into account you use for email sending and reconfirm your new password
:authentication => 'plain'
# ActionMailer Config
config.action_mailer.default_url_options = {:host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
# change to false to prevent email from being sent during development
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "example.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: "your_mail#gmail.com",
password: "your_password"
}
After making your development.rb file like this, then if you have problem means please login to your gmail account, which is used in the development.rb file.
Then problem will be solved.