Zoho ActionMailer Rails 5.0.1 - ruby-on-rails

What configuration do I need to send email from a rails application with Zoho?
With this configuration:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => 'smtp.zoho.com',
:port => 465,
:user_name => ENV['NOREPLY_USERNAME'],
:password => ENV['NOREPLY_PASSWORD'],
:authentication => :login,
:ssl => true,
:tls => true,
:enable_starttls_auto => true
}
I get this error:
Net::SMTPAuthenticationError (535 Authentication Failed):
With the same configuration but port 587 instead I get this error:
OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=unknown state: unknown protocol):
I have made sure that NOREPLY_USERNAME and NOREPLY_PASSWORD are the correct values.
Any help would be appreciated.

Emailed Zoho about this and they told me they checked and my email was hosted in Europe, so they told me to change to smtp.zoho.eu and use 465 SSL or 587 TLS. smtp.zoho.eu worked with 465 SSL and there are no errors and the emails are sent successfully.

Related

OpenSSL::SSL::SSLError: hostname "smtp.gmail.com" does not match the server certificate

This is what i have setup in setup_email.rb file,
if Rails.env.production?
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "gmail.com",
:user_name => "username",
:password => "mypass",
:authentication => "login",
:enable_starttls_auto => true
}
end
This code works in development and staging envoirnment.
This code was working fine on production, suddenly after several days it stopped working and i am getting error message.
I have tried setting up openssl_verify_mode: none still does'nt work.
Then i changed gmail account but getting same error. Seems like some
server side error
Error:
OpenSSL::SSL::SSLError: hostname "smtp.gmail.com" does not match the
server certificate
I have tried different methods out there on internet but its not working. Any help would be appreciated.
use
openssl_verify_mode: OpenSSL::SSL::VERIFY_NONE
or
openssl_verify_mode: 'none'
In case this answer shows up for others, I had the same problem with a new Rails 7, Ruby 3.1 app.
In my instance, I send emails from the Rails app to a local Postfix instance which relays email to a commercial provider. Always worked fine for me for earlier apps.
My typical settings are:
config.action_mailer.smtp_settings = {
address: "localhost",
port: 25,
domain: "WHATEVERYOURDOMAINIS",
enable_starttls_auto: false,
openssl_verify_mode: OpenSSL::SSL::VERIFY_NONE
}
This usually works fine, but with the current app, I kept getting errors like this:
SSL_connect returned=1 errno=0 peeraddr=127.0.0.1:25 state=error: certificate verify failed (Hostname mismatch) (OpenSSL::SSL::SSLError)
Using the method to test mailers from this helpful post: https://makandracards.com/makandra/52335-actionmailer-how-to-send-a-test-mail-directly-from-the-console I find that using 0 or 'none' instead of OpenSSL::SSL:VERIFY_NONE does nothing, but it pointed me in the direction of the net-protocol gem, which also supports the disable_start_tls option.
I then adjusted my config to:
config.action_mailer.smtp_settings = {
address: "localhost",
port: 25,
domain: "WHATEVERYOURDOMAINIS",
openssl_verify_mode: 'none',
disable_start_tls: true,
}
This gets rid of the problem in my case, though clearly it's disabling TLS completely so only useful if you're relaying mail like me through a local mailer.

sendgrid port 2525 not working in Rails app

I am trying to use the Google Cloud offer for SendGrid in a Rails app. In my config/environment/production.rb, I have:
config.action_mailer.delivery_method = :smtp
# SMTP Settings for use with SendGrid
ActionMailer::Base.smtp_settings =
{
:user_name => "myusername",
:password => "mypassword",
:domain => "mydomain",
:address => "smtp.sendgrid.net",
:port => 2525,
:authentication => :plain,
:enable_starttls_auto => true
}
It connects instantly and instantly I get an error:
Net::SMTPAuthenticationError (535 Authentication failed: Bad username / password
I can go there on the web and login with the same credentials, no problem. Anyone have any ideas why this is happening?
This turned out to be an rvm issue. Uninstalling and reinstalling rvm fixed this.

Rails - SSL error with Devise

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.

SSL Error when sending email via amazon-ses-mailer gem

I found this post Using Amazon SES with Rails ActionMailer and followed the examples found on https://github.com/abronte/Amazon-SES-Mailer but I'm getting this error when sending the mail
"SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed"
config/environments/development.rb:
config.action_mailer.delivery_method = AmazonSes::Mailer.new(
:secret_key => 'AKIAJ*******',
:access_key => 'Ahs08*********'
)
sending message:
mailer = ActionMailer::Base.delivery_method = AmazonSes::Mailer.new(
:secret_key => 'AKI*******',
:access_key => 'Ah***********'
)
mailer.deliver( UserMailer.test(#this_user.email).encoded )
Why am I having SSL Errors here? I tried another configuration using smtp with personal gmail account and its sending the email just fine. Is it a problem with SES? How do I fix this?
I don't think you need the SES Mailer gem anymore. SES used to support TLS wrappers only but as of March 7th 2012...
Amazon SES now supports STARTTLS
As stated in an answer at this SO question. It should be as simple as...
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "email-smtp.us-east-1.amazonaws.com",
:user_name => "..." # Your SMTP user here.
:password => "...", # Your SMTP password here.
:authentication => :login,
:enable_starttls_auto => true
}

What is wrong with my Rails SMTP config?

I was given this smtp server address: klee.cdlib.org (behind our firewall and does not need password/login) and my own local address where my dev application is running is http://128.48.204.195:3000
Here are my current configurations in the development.rb file:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "klee.cdlib.org",
:port => 587,
:domain => 'klee.cdlib.org', #'http://128.48.204.195:3000',
# :user_name => '',
# :password => '',
:authentication => 'plain',
:enable_starttls_auto => true }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
This gives an error:
Net::SMTPFatalError (550 5.7.1 <my#email.com>... Relaying denied
I am also not sure about the difference between domain and address fields. What should be in which? :) And what else am I possibly doing wrong to get this error?
Thanks,
Alex
Your rails setup seems ok. Denied relaying is probably raised because the mail server actually does not allow relaying any mails for mails from 128.48.204.195. It's possible that the mail server configuration is not configured for that or perhaps it's configured to relay mails from klee.cdlib.org which has no reverse DNS entry.

Resources