What does :tls => true do in SMTP settings in Rails 5?

2.2k Views Asked by At

I'm using Sendgrid on a Rails 5.2 application and was getting a Net::ReadTimeout error when trying to send an email. The post here https://github.com/mikel/mail/issues/639#issuecomment-29016055 suggested adding :tls => true to the SMTP settings. That worked, but it seems like an old solution and I'd like to understand what it's doing and why it worked.

This is my SMTP setup that gave the Net::ReadTimeout error:

ActionMailer::Base.smtp_settings = {
  :user_name => 'username',
  :password => 'password',
  :domain => 'mydomain.com',
  :address => 'smtp.sendgrid.net',
  :port => 465,
  :authentication => :plain,
  :enable_starttls_auto => true
}

This is the update that's working.

ActionMailer::Base.smtp_settings = {
  :user_name => 'username',
  :password => 'password',
  :domain => 'mydomain.com',
  :address => 'smtp.sendgrid.net',
  :port => 465,
  :authentication => :plain,
  :enable_starttls_auto => true,
  # this line added
  :tls => true
}
1

There are 1 best solutions below

1
On

Email is effectively a plaintext communication sent from email clients to receiving email servers or from one server to another. This design limitation leaves the content of a message in transit open for anyone to eavesdrop; from a wireless hotspot at the airport or coffee shop to your ISP and internet backbone providers that carry your messages throughout the world.

Transport Layer Security (TLS) helps solve this issue by offering encryption technology for your message while it is “in transit” from one secure email server to another. That is, TLS helps prevent eavesdropping on email as it is carried between email servers that have enabled TLS protections for email. Just as TLS can be used to secure web communications (HTTPS), it can secure email transport. In both applications, TLS has similar strengths and weaknesses. To maximize the content security and privacy, TLS is required between all the servers that handle the message including hops between internal and external servers.

Key features of TLS includes:

  • Encrypted messages: TLS uses Public Key Infrastructure (PKI) to encrypt messages from mail server to mail server. This encryption makes it more difficult for hackers to intercept and read messages.

  • Authentication: TLS supports the use of digital certificates to authenticate the receiving servers. Authentication of sending servers is optional. This process verifies that the receivers (or senders) are who they say they are, which helps to prevent spoofing.

For reference