How do I send signed emails from ActionMailer? - ruby-on-rails

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.

Related

What is the difference between using `:plain` vs `:login` in active mailer smtp settings?

What is the difference between using :plain vs :login in active mailer smtp settings as authentication ?
PLAIN
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
LOGIN
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :login,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
In different tutorial about configuring smpt setting especially for send-grid i have seen these been used.
both of them seems to be be working, so what is the difference between these two?
and which one is recommended and why ?
I headed :plain use base64 encoding to obfusticate the credentials, so is that the safest one ?
Long story short as you are using TLS your credentials are safe as they are being exchanged on an encrypted connection.
According to ActionMailer documentation here irrespective of authentication :plain or :login the password is always Base64 encoded. The problem with Base64 encoding is that it can be easily decoded by anybody eavesdropping in on the SMTP communication. So both of these authentication mechanisms are really the same in terms of security.
However as you are using TLS the connection is encrypted and the Base64 credentials are sent over this encrypted connection making it secure. If you were not using TLS then it would be better to use :cram_md5 instead of :login or :plain to secure the credentials.

Which are the smtp_settings for sending email with an account that uses Exchange?

I've configured smtp_settings for sending emails under Google Apps accounts several times, but now that I need to configure it for an email account using exchange it throws me execution expired message with the following settings:
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => 'smtp',
:port => 995,
:domain => 'domain',
:user_name => 'username',
:password => 'password',
:authentication => :plain,
}
The smtp, domain, user name and password were given to me by the client. The port I think it must be 995 (as it uses SSL).
Any ideas?
Well, I figured that the port was 25 instead of 995 and the authentication was login instead of plain.

Using ActionMailer with a company Gmail account

I'm not sure if this belongs in server fault or here feel free to move it if it makes more sense somewhere else. I've seen the examples for setting up the smtp settings and using ActionMailer with Gmail and confirmed that they work for me.
Basically it looks like this for me:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => '<username>',
:password => '<password>',
:authentication => 'plain',
:enable_starttls_auto => true }
What I need to do now is to send an email to an address that isn't a plain Gmail account and yet, at it's core, is Gmail. My company uses whatever google's email service that allows you to use gmail but for the addresses to be listed as username#my.company.com rather than #gmail.com. I know for a fact that you can't simply log into our mail at the main gmail site so I assume our domain is different. Or something.
At the moment, when I simply use my own company user/pass I get an error message telling me that the user/pass was wrong. But I'm guessing the issue is that I'm trying to mail from the gmail variant of my username.
I have confirmed that our smtp server, as far as Thunderbird is concerned, is the normal gmail smtp, that our port is still 587, and that we are using TLS. What do I need to change here so that I can send an email to one of these addresses? Thanks.
I have my own domain setup at google for mail, the url to log into that directly is
http://mail.google.com/a/my.company.com
My rails app that sends mail through that account, has
:domain => "my.company.com"
as well as all the other fields you have.
"<user_name>" needs to be the whole email address, not just the user name.
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'busiess.com',
:user_name => 'username#company.com',
:password => 'password',
:authentication => 'plain',
:enable_starttls_auto => true

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'
}

Delivery issues with Rails + Gmail SMTP in Dreamhost

I just released a Rails app in Dreamhost and I'm using Google Apps for my domain to handle Emai. I created the admin#domain.com account to serve as the sender authentication.
I installed smtp-tls plugin and my smtp conf is:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "www.domain.com",
:authentication => :plain,
:user_name => "admin#domain.com",
:password => 'secret'
}
The problem: Emails sometimes arrives, and sometimes don't. The recipient addresses are not exclusively Yahoo or GMail accounts, so I think it's not a spam issue. Any ideas? Thanks!
If you want better tracking of whether or not your emails are getting where you're trying to send them, checkout PostageApp:
http://postageapp.com/

Resources