Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Rails 3 and ActionMailer, is it possible to send email using TLS over SSL (Not StartTLS)?

I would like to use ActionMailer to send emails from my rail app. I have an existing mail server that I would like to use, however it only supports SSL/TLS on port 465. It does not, however, support StartTLS (typically on port 587).

Can anyone suggest a way of achieving this? As far as I can tell there is no support out of the box for this. I am using Rails 3.0.7.

like image 283
Alan Heywood Avatar asked Jul 05 '11 08:07

Alan Heywood


People also ask

What is ActionMailer?

1 Introduction. Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from ActionMailer::Base and live in app/mailers. Those mailers have associated views that appear alongside controller views in app/views.

What does StartTLS stand for?

StartTLS is a protocol command used to inform the email server that the email client wants to upgrade from an insecure connection to a secure one using TLS or SSL. StartTLS is used with SMTP and IMAP, while POP3 uses the slightly different command for encryption, STLS.

How do I use mailer in Ruby on Rails?

Mail will automatically Base64 encode an attachment. If you want something different, encode your content and pass in the encoded content and encoding in a Hash to the attachments method. Pass the file name and specify headers and content and Action Mailer and Mail will use the settings you pass in.


1 Answers

Yes, you can specify the :ssl option.

Set the following values in your config/environments/production.rb file:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
    address: 'mail.example.com',
    port: 465,
    domain: 'example.com',
    user_name: '[email protected]',
    password: 'password',
    authentication: 'plain',
    ssl: true,
}

This works with my ISP (Bluehost) for sending mail.

like image 185
Matt Connolly Avatar answered Nov 15 '22 15:11

Matt Connolly