Skip to content

Instantly share code, notes, and snippets.

@airblade
Created June 25, 2012 14:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save airblade/2988937 to your computer and use it in GitHub Desktop.
Save airblade/2988937 to your computer and use it in GitHub Desktop.
Monkey-patch enabling Rails 2.3 to use SMTP over SSL
# config/initializers/email.rb
# Monkey-patch to enable ActionMailer to send STMP email over SSL.
# Necessitated by Fastmail mandating SSL by 30 June 2012.
module ActionMailer
class Base
def perform_delivery_smtp(mail)
destinations = mail.destinations
mail.ready_to_send
sender = (mail['return-path'] && mail['return-path'].spec) || Array(mail.from).first
smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port])
smtp.enable_tls if smtp_settings[:ssl] && smtp.respond_to?(:enable_tls)
smtp.enable_starttls_auto if smtp_settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto)
smtp.start(smtp_settings[:domain], smtp_settings[:user_name], smtp_settings[:password],
smtp_settings[:authentication]) do |smtp|
smtp.sendmail(mail.encoded, sender, destinations)
end
end
end
end
ActionMailer::Base.smtp_settings = {
address: 'mail.messagingengine.com',
port: 465,
domain: 'yourdomain.com',
user_name: 'your_username',
password: 'xxxxxxx',
authentication: :plain,
enable_starttls_auto: false,
ssl: true
}
@greyrain
Copy link

Thank you very much! This monkey-patch saves my soul!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment