Rails - SSL error with Devise - ruby-on-rails

I've used Devise before with little trouble. The only things I can think of that are different for this project is that I'm trying omniauth (I've only added the gems - no functionality yet) for the first time and I've switched from Windows to Ubuntu 14.04
When I try to sign up a new user with Devise I get the error:
SSL_connect returned=1 errno=0 state=unknown state: unknown protocol
Extracted source (around line #586):
584 logging "TLS connection started"
585 s.sync_close = true
586 s.connect
587 if #ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
588 s.post_connection_check(#address)
589 end
In config/environments/development.rb I have:
config.action_mailer.default_url_options = { :host => 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => 'smtp.gmail.com',
:port => 587,
:tls => true,
:domain => 'gmail.com', #you can also use google.com
:authentication => :login,
:user_name => 'my_email#gmail.com',
:password => 'password'
}
I really don't understand this problem so any help at all will be much appreciated.

Try setting the SSL_Cert_file environmental variable to:
edit the ~/.bashrc file and add:
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
If that doesn't work and you are using RVM maybe setting the path to: ~/.rvm/usr/ssl/cert.pem
Before you make any changes just note down what the path currently is so that you can set it back if needed.

Related

Net::SMTPFatalError (550 Unauthenticated senders not allowed; tried varoius methods to solve the issue [duplicate]

I have integrated Sendgrid settings on a Rails 4 server. These settings work fine for development environment. But this is giving error on production environment.
Net::SMTPFatalError (550 Cannot receive from specified address <simmi#mydomain.com>: Unauthenticated senders not allowed)
config/initializers/email_setup.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:domain => DOMAIN,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => "plain",
:enable_starttls_auto => true
}
config/initializers/devise.rb
config.mailer_sender = 'simmi#mydomain.com'
config/environments/production.rb
# Default URL
config.action_mailer.default_url_options = { host: 'mysite.mydomain.com' }
DOMAIN = 'mysite.mydomain.com'
According to sendgrid support team, this error comes when username or password are incorrect. I tried logging manually into the smtp server through telnet and it was working.
On my server commandline, I followed these steps:
telnet smtp.sendgrid.net 587
EHLO
AUTH LOGIN
Enter username in Base64
Enter password in Base64
Link to convert text into Base64 - http://www.opinionatedgeek.com/dotnet/tools/base64encode/
The ENV variables were somehow not working on my production environment. As a workaround, I tried adding the username and password directly and it worked.
I have also faced the same problem and fixed it by adding the following:
config/environment.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:domain => DOMAIN,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => "plain",
:enable_starttls_auto => true
}
ActionMailer::Base.default_url_options = { host: 'mysite.mydomain.com' }
config/application.rb
ActionMailer::Base.delivery_method = :smtp
The letter_opener gem is very useful if you want to test sending emails in development mode.
If you want to overwrite the letter_opener, add the following configuration
config/environments/development.rb
ActionMailer::Base.delivery_method= :letter_opener
And also add the port under ActionMailer::Base.smtp_settings.
You are probably loading your environment variables after you are trying to initialize your mailer. You can do the initialization directly after loading your variables to be sure that they exist.
Set up a config file with your username and password variables:
# config/mailer.yml
production:
SENDGRID_USERNAME: 'username'
SENDGRID_PASSWORD: 'password'
Set up an initializer file:
# config/initializers/mailer.rb
if Rails.env.production?
config_path = File.expand_path(Rails.root.to_s + '/config/mailer.yml')
if File.exists? config_path
ENV.update YAML.load_file(config_path)[Rails.env]
end
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV["SENDGRID_USERNAME"],
:password => ENV["SENDGRID_PASSWORD"],
:domain => "yourdomain",
}
end
If your production environment is Heroku:
Login to your Heroku account and select the application. Under "Settings", click the "Reveal Config Vars" button. Enter in your sendgrid key and value pairs, then submit. Run: heroku restart.

Net::OpenTimeout in Users

I am using actionmailer to send registration verification details of devise to users but I am getting following error:
Net::OpenTimeout in Users::RegistrationsController#create
my development.rb looks like:
config.action_mailer.default_url_options = { :host => 'http://localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 25,
:domain => 'gmail.com',
:user_name => 'example#gmail.com',
:password => 'secret',
:authentication => 'plain',
:enable_starttls_auto => true,
:ssl => true
}
I use this question and added
#disable ipv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
command:
cat /proc/sys/net/ipv6/conf/all/disable_ipv6
return 1. It didn't make difference to my error. Also tried changing port from 587 to 2525.
So I tried establish connection with server from command line:
telnet smtp.gmail.com 2525
got:
Trying 74.125.68.108...
Trying 74.125.68.109...
Trying 2404:6800:4003:c02::6c...
telnet: Unable to connect to remote host: Network is unreachable
I even tried adding firewall rules using this. I followed second method (ufw) but I am still getting same error.

Rails 3 action mailer production OpenSSL::SSL::SSLError: hostname does not match the server certificate

I am facing problem with Open SSL certificate error while sending email in production server. Everything is working fine in development mode. Below is my configuration code in production mode.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:authentication => "plain",
:enable_starttls_auto => true,
:user_name => 'xxxxxxx',
:password => 'xxxxx',
:openssl_verify_mode => 'none'
}
I have already looked at the solution in previous post But, that does not solve my problem.
Could anyone kindly help with this one?
Try adding the domain name in smtp_setings
:domain => 'www.your-domain-name.com'

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.

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