Skip to content

Instantly share code, notes, and snippets.

@postnati
Created January 20, 2011 02:14
Show Gist options
  • Save postnati/787290 to your computer and use it in GitHub Desktop.
Save postnati/787290 to your computer and use it in GitHub Desktop.
Send email from Ruby using google's smtp server
require 'net/smtp'
def send_email(from, from_alias, to, to_alias, subject, message)
msg = <<END_OF_MESSAGE
From: #{from_alias} <#{from}>
To: #{to_alias} <#{to}>
Subject: #{subject}
#{message}
END_OF_MESSAGE
smtp = Net::SMTP.new 'smtp.gmail.com', 587
smtp.enable_starttls
# smtp.start(YourDomain, YourAccountName, YourPassword, :login)
smtp.start("pattison@atomicobject.com", "pattison@atomicobject.com", "abc123", :login) do |smtp|
smtp.send_message msg, from, to
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment