Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nisanthchunduru/d341ab22dede19e572d0e8152393e93a to your computer and use it in GitHub Desktop.
Save nisanthchunduru/d341ab22dede19e572d0e8152393e93a to your computer and use it in GitHub Desktop.
send email to gmail (STARTTLS) using ruby >=1.8.7
# send email using STARTTLS; Net::SMTP#enable_starttls requires ruby >=1.8.7
# this hack is needed for rails <2.3; apparently >=2.3 has something for this already
ActionMailer::Base.class_eval do
private
def perform_delivery_smtp(mail)
destinations = mail.destinations
mail.ready_to_send
smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port])
smtp.enable_starttls
smtp.start(smtp_settings[:domain],
smtp_settings[:user_name],
smtp_settings[:password],
smtp_settings[:authentication]) do |smtp|
smtp.sendmail(mail.encoded, mail.from, destinations)
end
end
end
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => 'your.email@yourdomain.com',
:password => 'secret',
:authentication => :plain,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment