Net::SMTPAuthenticationError in UsersController#create - ruby-on-rails

our Rails 3.2 application's "resend activation code" mail feature was working until the code was transferred from the previous developer to us. Now we get this error
Net::SMTPAuthenticationError in UsersController#create
Our mail settings remain untouched like this:
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 587,
:domain => "example.com",
:user_name => "username",
:password => "password",
:authentication => "plain",
:enable_starttls_auto => true
}
We are somehow not able to figure it out as to why the email stop's working.
We have checked the gmail server also responding back to us via telnet.
We have also enabled the Less Secure Apps feature of Gmail's in Security -> Account permissions -> Access for less secure apps
Thanks in advance.

You mentioned using Gmail's settings, I'd say you should try this:
ActionMailer::Base.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
user_name: ENV['GMAIL_USERNAME'],
password: ENV['GMAIL_PASSWORD'],
authentication: :plain,
enable_starttls_auto: true
}
If you're using Sendgrid, as above you should have something like:
ActionMailer::Base.smtp_settings = {
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
domain: 'heroku.com', #for your helo domain
address: 'smtp.sendgrid.net',
port: 587,
authentication: :plain,
enable_starttls_auto: true
}
Don't forget to define your ENV variables appropriately.
You can find more discussion around this here

Related

Rails Gmail contact form - works on localhost but not when deployed to Heroku

I am having a strange problem, I am coding a GMAIL contact form - which will use an existing Gmail username and password to send emails to a pre-specified Gmail account.
The issue I am having is that when I run everything locally it works just fine. Once I deploy to Heroku on the other hand ... I am not receiving the messages. When I run: heroku logs -t it seems to show that the message has been sent but nothing is still coming through.
Configuration:
ActionMailer::Base.default_url_options = { :host => 'domain.herokuapp.com' }
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,
:enable_starttls_auto => true,
:domain => 'domain.herokuapp.com',
:user_name => ENV['GMAIL_USERNAME'],
:password => ENV['GMAIL_PASSWORD'],
:authentication => "login"
}
Note:
domain.herokuapp.com has just been subbed in for my actual domain.
Screen shot of server logs:
Does anyone have any idea of why this is not working or can point me to a resource to get this resolved?
I had a similar problem, it was connected to the configuration in config/enfironments/production.rb file i had
config.action_mailer.default_url_options = { host: 'http://barteringapps.herokuapp.com' }
I was able to solve this problem by changing the address. In development it should be http://127.0.0.1:3000, while it should be your domain in production.
Also your gmail domain is not correct, you should have gmail.com as domain
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: ENV["GMAIL_DOMAIN"],
authentication: "plain",
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"],
enable_starttls_auto: true
}
I followed this post, but be careful when configuring the default_url_options as it would give me problems with facebook omniauth
https://rubyonrailshelp.wordpress.com/2014/01/02/setting-up-mailer-using-devise-for-forgot-password/

How to add password to smtp settings without comprimizing account security

I am trying to set up an email contact form on my Rails app, but I am having trouble figuring out how to get the settings in config/production to read my password, without comprising my account.
Here are a heroku configs:
Jillians-MacBook-Pro-2:noises3 Jillian$ heroku config
=== noises Config Vars
DATABASE_URL: xxxdatabaseurlxxx
LANG: en_US.UTF-8
RACK_ENV: production
RAILS_ENV: production
RAILS_SERVE_STATIC_FILES: enabled
S3_BUCKET: muzack
SECRET_KEY_BASE: xxxsecretxxx
gmail_password: xxxmy_passwordxxx
gmail_username: xxxmy_emailxxx
And my smtp settings, in config/production.rb:
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: ENV['gmail_username'],
password: ENV['gmail_password'],
authentication: :plain
}
And in config/initializers/smtp_settings.rb:
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "jho3292#gmail.com",
:password => WHAT DO I DO HERE???
:authentication => :plain,
:enable_starttls_auto => true
}
Does anyone know how to do this correctly?

Setup SMTP settings for sending mail in rails

I've followed the following tutorial to create a contact form.
Everything was fine, but as tutorial says For real e-mail delivery, you should set up SMTP in the environment settings. how can I set up SMTP?
As Suggested in this link I created and edited the smtp_settings.rb; But No luck at all. It still doesnot send the email to the real user.
smtp_settings.rb
if Rails.env.production?
Gitlab::Application.config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
user_name: "myaccount#gmail.com",
password: "abcpassword",
domain: "mail.google.com",
authentication: :login,
enable_starttls_auto: true
}
end
It may be because your smtp_settings.rb file isn't being found by Rails, or that the delivery_method line isn't being recognised..
Try moving the file to /config/initializers/smtp_settings.rb if it isn't there already, and changing the contents slightly to
if Rails.env.production?
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
user_name: "myaccount#gmail.com",
password: "abcpassword",
domain: "mail.google.com",
authentication: :login,
enable_starttls_auto: true
}
end
It could also be that the settings are only applied for production, if you're trying this out locally in development you'll need to remove the first line if Rails... and the last line end like so..
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
user_name: "myaccount#gmail.com",
password: "abcpassword",
domain: "mail.google.com",
authentication: :login,
enable_starttls_auto: true
}
After any changes to this file you'll need to restart your rails server or rails console session for the changes to take effect.

Will switching on two-factor authentication stop my Heroku app accessing the Gmail server?

In the past, I've sent email from Heroku apps using the Gmail server, like this:
config.action_mailer.deconfig.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'derp'
:user_name => 'derp.bot',
:password => 'derp42069',
:authentication => 'plain',
:enable_starttls_auto => true }
Since then I've enabled two-factor authentication for most of my domains. Before I do the same for my latest domain, will in wreck havoc with Rails code like you see above?
If the change does break your code, you could fix work around it by using an application-specific password.

rails email error - 530-5.5.1 Authentication Required.

trying to send email form Ruby on Rails but getting this:
SocketError in UsersController#create
getaddrinfo: nodename nor servname provided, or not known
My environments/development.rb file has:
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "my_company.org",
authentication: "plain",
enable_starttls_auto: true,
user_name: "my_username#my_company.org",
password: "my_pass"
}
and
config.action_mailer.delivery_method = :smtp
and
config.action_mailer.default_url_options = { :host => 'localhost:5000' }
# 5000 rather than 3000 as I am using foreman.
I did the same using my Gmail, following are my configurations, try and see it if works
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:authentication => :plain,
:user_name => "<my gmail>#gmail.com",
:password => "<my gmail password>",
:openssl_verify_mode => 'none'
}
and please note the
:openssl_verify_mode => 'none'
section to skip the SSL errors.
But sorry, I have no idea what the error is, probably you try to use the Gmail SMTP server with another domain name.
In case others face the same issue, I just wanted to add that I had the exact same problem trying to implement a mailing system with gmail in my Rails API, and adding :openssl_verify_mode => 'none' did not solve the problem for me.
Instead, installing the figaro gem and then adding my environment variable in application.yml like so:
gmail_username: "myemail#gmail.com"
gmail_password: "mypassword"
did the trick for me.
(and dont forget to change you SMTP settings: )
user_name: ENV['gmail_username'],
password: ENV['gmail_password'],

Resources