Rails ActionMailer configuration for Zoho - ruby-on-rails

Anyone have luck configuring ActionMailer to send email via a Zoho account?
These are my settings:
ActionMailer::Base.smtp_settings = {
:address => "smtp.zoho.com",
:port => 465,
:domain => 'example.com',
:user_name => 'steve#example.com',
:password => 'n0tmypa$$w0rd',
:authentication => :login
}
However, calling .deliver times out:
irb(main):001:0> AdminMailer.signup_notification('asfd').deliver
Timeout::Error: Timeout::Error
from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill'
from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:140:in `rbuf_fill'
from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
from C:/Ruby193/lib/ruby/1.9.1/net/smtp.rb:929:in `recv_response'
from C:/Ruby193/lib/ruby/1.9.1/net/smtp.rb:552:in `block in do_start'
from C:/Ruby193/lib/ruby/1.9.1/net/smtp.rb:939:in `critical'
from C:/Ruby193/lib/ruby/1.9.1/net/smtp.rb:552:in `do_start'
from C:/Ruby193/lib/ruby/1.9.1/net/smtp.rb:519:in `start'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/smtp.rb:144:in `deliver!'
The help docs say to use port 465 and SSL authentication. I've tried with and without :enable_starttls_auto => true but it still times out.
Specifically, the docs specify the following settings:
> Email Address: Username#yourdomain.com
> User Name format: Username#yourdomain.com
> Secure Connection (SSL) Yes
> Outgoing Mail Server Name: smtp.zoho.com
> Outgoing Port No.: 465
> Outgoing Mail Server requires authentication: Yes
Any ideas?
p.s. I've configured Outlook to use the settings in the help docs and outgoing email works fine. telnet to smtp.zoho.com 465 also connects.

# Action Mailer
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.zoho.com",
:port => 465,
:user_name => 'someone#somewhere.com',
:password => 'password',
:authentication => :login,
:ssl => true,
:tls => true,
:enable_starttls_auto => true
}
That worked for me. Your settings might be fine some local networks block these kinds of packets. I had to test it through my 3G network.

FYI:
Let's say your domain is abc.com.
Let's say you have 'default from' on your mailer with a different domain, e.g.
default from: "\"Elephant\" <el#ephant.com>"
This will not work unless you change your 'default from' using the same domain on your zoho account.
So,
default from: "\"Elephant\" <el#abc.com>"
will work.

I'm not sure if Zoho have changed their security settings, but #Tyrel Richey's accepted answer didn't work for me. However, the following does:
/config/initializers/action_mailer.rb..
# ActionMailer email configuration
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => ENV['SMTP_ADDRESS'],
:port => ENV['SMTP_PORT'],
:domain => ENV['SMTP_DOMAIN'],
:user_name => ENV['SMTP_USERNAME'],
:password => ENV['SMTP_PASSWORD'],
:authentication => :login,
:enable_starttls_auto => true
}
Where..
:address = smtp.zoho.com
:port = 587
:domain is localhost in development, and the live URL in production (e.g. example.com)

I have mail sending with Rails 4.2.3 like so...
# config/environments/development.rb
Rails.application.configure do
#...
config.action_mailer.default_url_options = { host: 'domain' }
config.action_mailer.smtp_settings = { address: 'smtp.zoho.com', port: 465, user_name: 'username#domain.com', password: 'mypassword', authentication: :login, ssl: true }
end
You can of course use this in production as well by adding this to config/environments/production.rb
I also set the email address in config/initializers/devise.rb so I can send password reset instruction.
config.mailer_sender = 'noreply#truhawk.com'
References
https://www.zoho.com/mail/help/zoho-smtp.html
http://guides.rubyonrails.org/action_mailer_basics.html

These settings worked for me in production.
Rails.application.routes.default_url_options[:host] = 'eyehawk.io'
config.action_mailer.default_url_options = { :host => 'eyehawk.io' }
config.action_mailer.perform_caching = false
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"
config.action_mailer.smtp_settings = {
:address => "smtp.zoho.com",
:port => 587,
:domain => "zoho.com",
:user_name => "admin#eyehawk.io",
:password => ENV['SMTP_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true
}

Using smtp.zoho.eu instead of smtp.zoho.com as address did the trick for me.

Related

Not able to deliver the mail in canvas lms? What configuration setting i am missing?

This is my outgoing_mail.yml files
If click on the forgot password link It is showing in the delayed_job.log
My email is deliver got stuck please help me.
production:
address: "smtp.gmail.com"
port: "587"
user_name: "xxxxxx#gmail.com"
password: "password"
authentication: "plain" # plain, login, or cram_md5
domain: "domain_name.com"
outgoing_address: "xxxxxx#gmail.com"
default_name: "Instructure Canvas"
My SMTP settings are right but the in site admin settings there is feature option section there is an option "Use remote service for notifications" is No so is if you use remote service like mailer etc. this option turns into off.
And It's working fine.
In config/environments/production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host:'your host', port: 'xxx' }
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 => 'abc.com',
:user_name => "xxxx#mail.com",
:password => "xxxx",
:authentication => :plain,
:enable_starttls_auto => true
}

Rails w/devise authentication what is the configuration of iRedMail?

We're using successfully iRedMail in 4 email servers (8 domains) for our own email accounts.
We develop web apps based on RoR. We would like to know what is the iRedMail configuration for sending to users, via rails and devise gem, https://github.com/plataformatec/devise, the password reminds, emails confirmations, etc.. What is the difference between address and domain? How to test?
After Googling and posting in iRedMail forum unsuccessful, we only find smt gmail config, please find below.
Thanks in advance!
==== DEVISE config/environments/development.rb ====
SMTP GMAIL CONFIG:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "mail.google.com",
:user_name => "my#gmail.com",
:password => "mypassword",
:authentication => :plain,
:enable_starttls_auto => true
}
==== BACK-END ====
iRedMail 0.9.7 MARIADB edition.
Debian GNU/Linux 9 (stretch) in a fresh OVZ-6GB
Mysql/MariaDB w/adminer
Apache/2.4.25 (Debian)
PHP 7.0.19-1
Ruby 2.5.0, Rails 5.1.5 and Phusion Passenger 5.2.1
No errors: /var/log/iredapd/iredapd.log
=============================
Editing DEVISE config/environments/development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.smtp_settings = {
:address => "mx.coopeu.com",
:port => 587,
:domain => "mx.cooopeu.com",
:user_name => "coopeu#coopeu.com",
:password => "password",
:authentication => :plain,
:enable_starttls_auto => true
}
Also raising error:
Net::SMTPFatalError in ConfirmationsController#create
554 5.7.1 : Recipient address rejected: Sender is not same as SMTP authenticate username
It means you use user "coopeu#coopeu.com" for SMTP authentication, but specify user "someone-else#somedomain.com" as the sender address.
If you need to allow the sender address mismatch for this smtp user, you can add one setting in
/opt/iredapd/settings.py
to allow it, like below:
ALLOWED_LOGIN_MISMATCH_SENDERS = ['coopeu#coopeu.com']
Restarting iredapd after modified "settings.py".
and it's working right

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.

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'

Completed 500 Internal Server Error in Rails 4 Devise Signup process

When I go to signup a new user on the site I fill in the form, click submit, and it sits there for a few seconds, then dispays 'We're sorry, but something went wrong.'
The Log is below...
https://gist.github.com/th3cuda/225f1352a7cfeee3f8f8
This is deployed on digitalocean.
production.rb
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
config.action_mailer.default_url_options = { :host => 'MY_HOST' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.MY_DOMAIN.com',
:port => 465,
:domain => 'MY_DOMAIN',
:user_name => 'MY_EMAIL',
:password => 'PASSWORD',
:authentication => 'plain',
:enable_starttls_auto => true
}
end
Since it's taking a while, it could be looking for sendmail (it uses /usr/sbin/sendmail by default) to send the email.
I would make sure that it's in place, that it can be used by the app, and that the config/(Dev, Prod, etc.) allows it to deliver email.
Is any of that helpful? Let me know what you find so I can give a better answer.
Sorry to add another answer, but formatting here is important.
config.action_mailer.default_url_options = { :host => 'MY_HOST' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtpout.secureserver.net',
:port => 80,
:domain => 'www.example.com',
:user_name => 'johndoe#example.com',
:password => 'yourpassword',
:authentication => 'plain'
}
end
Notice I removed the starttls option, and set port to 80. Obviously, replace with your real values. If you're using constants, please avoid using those until this gets resolved.

Resources