hostname does not match the server certificate - cannot send email - ruby-on-rails

I am using Pony mail to send email messages (because I could never get ActionMailer to work on my local Windows box).
The code in my user_mailer.rb file include this call to the Pony.mail method:
Pony.mail({
:to => email_address,
:from => 'MyChairSales <support#mychairsales.com>',
:subject => subject,
:body => email_body,
:html_body => html_body,
:via => :smtp,
:via_options => {
:address => 'mail.mychairsales.com',
:port => '25',
:enable_starttls_auto => true,
:user_name => 'mychairs',
:password => 'thepassword',
:domain => "mychairsales.com" # the HELO domain provided by the client to the server
}
})
This was working (I have received email using this method) but is now failing with the error "hostname does not match the server certificate".
Here is the top of the stack trace:
["/usr/lib64/ruby/1.9.3/openssl/ssl-internal.rb:121:in `post_connection_check'",
"/usr/lib64/ruby/1.9.3/net/smtp.rb:585:in `tlsconnect'", "/usr/lib64/ruby/1.9.3
/net/smtp.rb:560:in `do_start'", "/usr/lib64/ruby/1.9.3/net/smtp.rb:519:in `start'",
"/home4/mychairs/ruby/gems/gems/mail-2.4.4/lib/mail/network/delivery_methods
/smtp.rb:144:in `deliver!'", "/home4/mychairs/ruby/gems/gems/mail-2.4.4/lib
/mail/message.rb:245:in `deliver!'", "/home4/mychairs/ruby/gems/gems/pony-1.4/lib
/pony.rb:166:in `deliver'", "/home4/mychairs/ruby/gems/gems/pony-1.4/lib
/pony.rb:138:in `mail'", "/home4/mychairs/rails_apps/chairsales/app/mailers
/user_mailer.rb:32:in `send_mail'", "/home4/mychairs/rails_apps/chairsales/app/mailers
/user_mailer.rb:23:in `send_password_reset_email'",...
Any guidance would be greatly appreciated!

A bit late but I also encountered this error but with the Ruby Mail gem. If your SMTP server supports TLS, it will attempt to use TLS and authenticate the SSL certificate. If the certificate is issued for a hostname other than the one used or if the certificate cannot be authenticated (for example if it's self-signed and you don't trust the CA), then it will fail with the error "hostname does not match the server certificate".
To get around it, use the :openssl_verify_mode option. This can be set to OpenSSL::SSL::VERIFY_NONE to do no verification of the certificate - it will still encrypt the SMTP session though. Or there are other options available within the OpenSSL library.
Using your example, it would be:
Pony.mail({
:to => email_address,
:from => 'MyChairSales <support#mychairsales.com>',
:subject => subject,
:body => email_body,
:html_body => html_body,
:via => :smtp,
:via_options => {
:openssl_verify_mode => OpenSSL::SSL::VERIFY_NONE,
:address => 'mail.mychairsales.com',
:port => '25',
:enable_starttls_auto => true,
:user_name => 'mychairs',
:password => 'thepassword',
:domain => "mychairsales.com" # the HELO domain provided by the client to the server
}
})
This also works for the Mail gem as well.

Related

How to configure Rails mailer with a non-gmail account?

I have a rails mailer that I want to configure with an email account that is non-gmail, and is accessed through outlook. the SMTP address is "smtp.us.exg7.exghost.com". The email is not #exghost.com.
I am running into a 504 5.7.4 unrecognized authentication type error.
Here is my configuration:
config.action_mailer.smtp_settings = {
:address => "smtp.us.exg7.exghost.com",
:port => "587",
:domain => "exghost.org",
:user_name => 'example#example.org',
:password => 'Password',
:authentication => "plain",
:enable_starttls_auto => true
}
Does anyone have any insight into this? I have tried various domains- exghost.com, us.exg7.exghost.com, example.org. I have tried changing authentication from "plain" to "login", but nothing seems to change the error.
I know that in gmail you have to allow third-party access, does this need to be done with other formats?

Mail not sending from ewebguru domain Rails

I have a domain techo.com (bought from ewebguru) and I'm tryng to send mail from my rails app but mail is not sending I'm using following code configuration in production and development :
{
:user => 'abcd#techo.com',
:password => '*********',
:domain => 'techo.com',
:port => 25,
:authentication => :none
}
somebody suggest me to do these :
User: mail id
Password: mail id password
SMTP Server: tecorb.com
SMTP Port: 25
POP Port: 110
SSL Authentication:None
I'm not getting how to configure these into my development.
Please suggest me.
As I see your code, you are missing :address key in the configuration. Address for ewebguru is mahanadi.ewebguru.net (may be this address can be change but same for my domain purchased from ewebguru). Try configuration like this :
ActionMailer::Base.smtp_settings = {
:user_name => 'abcd#techo.com',
:password => '*******',
:server => 'techo.com',
:address=>"mahanadi.ewebguru.net"
}
Hope this will work.

Rails EOFError (end of file reached) when saving a devise user

I'm getting this error in production when trying to create a user (i'm using the devise gem).
EOFError (end of file reached):
I hit this problem before and it was due to my smtp settings using zoho mail.
I believe my configuration below is what fixed the problem:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.zoho.com",
:port => 465,
:domain => 'example.com',
:user_name => 'user#example.com',
:password => 'password',
:authentication => :login,
:ssl => true,
:tls => true,
:enable_starttls_auto => true
}
Now we've added SSL to the site and I believe that is what is causing this error to occur now.
Does anyone have any insight into this error or zoho mail smtp settings with SSL?
This error was caused by not having my config/initializers/devise.rb specifying the correct email address for config.mailer_sender.
Also! I made this additional mistake and had the same issue: I used my own domain instead of the mail server domain for the "domain" variable.
Your environment variable should be:
GMAIL_DOMAIN=gmail.com
Or for the example above:
:domain => 'gmail.com',
I found one cause for the error here => https://stackoverflow.com/a/40354121/6264112
But this didn't solve my issue. While I wasn't getting any errors, my emails were still not working through Zoho so I found another solution that works perfectly for my needs...
1) Connect Zoho to gmail using SMTP. I setup my zoho email as an alias for my personal gmail account so zoho emails are forwarded to gmail and I can reply to them IN gmail FROM my zoho email address. This should be done anyways so you never have to login to zoho. Just do all emailing from gmail.
2) Connect ActionMailer to gmail account NOT zoho.
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:user_name => ENV["gmail_username"],
:password => ENV["gmail_password"],
:authentication => :plain,
:enable_starttls_auto => true
}
Now, I just need to specify the to and from values in the mailer like so:
def notify_admin (message_details)
#message_details = message_details
mail(to: "jesse#mydomain.com", subject: "Contact form filled out by: " + message_details[:name], from: message_details[:email])
end
This works when I want to send emails to myself as is the example above when someone submits the contact form.
It ALSO works when I want to send an email from my domain such as when they fill out the lead magnet. All I did was switch the to: and from: addresses.
Here's a working pony gem call.
Pony.mail({
:to => 'apotonick#gmail.com',
subject: "Pony ride",
body: "Awesome!",
from: "nick#trb.to", # this MUST be the sending Zoho email.
:via => :smtp,
:via_options => {
:address => 'smtp.zoho.com',
:port => '465',
:enable_starttls_auto => true,
ssl: true,
:user_name => 'nick#trb.to', # MUST be identical to :from.
:password => 'yourStrongPw',
:authentication => :login,
}
})
I had this issue, and I tried everything and still couldn't figure out what the issue was.
Let's face it, it's a SH!t message. What I did find though I was running my rails app locally with POW and its actually a POW error.
When I run rails server and do the same thing that caused the error, I actually got the real error message and was able to find I hadn't setup my controller correctly

Net::SMTPAuthenticationError 502 5.5.2 in Rails ActionMailer

i'm trying to send confirmation email to the user.
But i get following error:
Net::SMTPAuthenticationError (502 5.5.2 Error: command not recognized
Configuration in production.rb is following:
# Disable delivery errors, bad email addresses will be ignored
config.action_mailer.raise_delivery_errors = true
# set delivery method to :smtp, :sendmail or :test
config.action_mailer.delivery_method = :smtp
# these options are only needed if you choose smtp delivery
config.action_mailer.smtp_settings = {
:address => 'path_to_address_specified_by_my_hoster',
:port => 25,
:domain => 'my_domain.com',
:authentication => :plain,
:user_name => 'signup#my_domain.com',
:password => 'password'
}
I have created a mailbox in user profile at my hosting provider, named "signup#my_domain.com"
For created mailbox, they issued to me login and password:
login = verbose_login
password = verbose_password
I did't completely understood the exact format of :user_name.
Should i use
:user_name => "signup#my_domain.com"
or:
:user_name => "signup"
or:
:user_name => "verbose_login"
Or this field is specific to the mail server, and i must ask support of hosting provider ?
And what the difference between :authentication => :plain and :login ?
Thanks.
This works well for me:
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:user_name => 'my_nick#gmail.com',
:password => 'secret_password',
:authentication => 'login',
:enable_starttls_auto => true
}
more info here
Petr
I have got the same error recently, and the reason was incorrect format of recipients
recipient = IO.readlines(emails_filename).first
mail(:to => recipient, :subject => subject)
Don't forget to add strip to get clean email addresses.
I had the same problem, but it is just a google configuration issue.
For some reason Google was blocking access from unknown location (app in production), so to solve this you can go to http://www.google.com/accounts/DisplayUnlockCaptcha and click continue (this will grant access for 10 minutes for registering new apps).
On the other hand, you could login to your gmail account, then go to https://www.google.com/settings/security/lesssecureapps and enable the access to less secure applications, which was the solution for me!
Please try to login with browser once.
There might be some issue with login (it will ask captcha etc).
Once you successfully logged-in, then try with Rails Mailer.
It should work now.
This issue generally happens with test account as we do not login via browser usually.
Then mail providers ask for confirmation like captcha, dob or answer of security question etc.
You've to use ActionMaliler::Base instead of config
ActionMailer::Base.smtp_settings #try this
config.action_mailer.smtp_settings #instead of this
Change your smtp code to below. It should work now.
ActionMailer::Base.smtp_settings = {
:address => 'path_to_address_specified_by_my_hoster',
:port => 25,
:domain => 'my_domain.com',
:authentication => :plain,
:user_name => 'signup#my_domain.com',
:password => 'password'
}

How do I send signed emails from ActionMailer?

I'm using GMail as my SMTP server. I have that configuration working just fine:
# config/initializers/action_mailer.rb:
ActionMailer::Base.smtp_settings = {
:tls => true,
:address => "smtp.gmail.com",
:port => "587",
:domain => "www.example.org",
:authentication => :login,
:user_name => "admin#example.org",
:password => "it's a secret"
}
I also have a public/private RSA key pair in config/ssl/rsa.public and config/ssl/rsa.private.
What do I do to sign the emails before shipping them off to GMail's SMTP server?
I think you want ActionmailerX509. You need a certificate which you can a) buy for lots of money b) get for free from CAcert.org c) generate yourself. Everything you need to know is explained in the README.

Resources