Created
April 11, 2010 16:05
-
-
Save yeban/362842 to your computer and use it in GitHub Desktop.
Bare bones Ruby script to send emails using Gmail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
Tested with ruby 1.8.7 on a Debian machine, with my own gmail account. | |
ruby -rubygems "from name" "from email" "to name" "to email" "subject" "body" | |
=end | |
require 'net/smtp' | |
require 'tlsmail' | |
Net::SMTP.enable_tls OpenSSL::SSL::VERIFY_NONE | |
$SERVER = 'smtp.gmail.com' | |
$PORT = '587' | |
$DOMAIN = 'loclahost'#HELO domain | |
$USERNAME = 'your usernanme' | |
$PASSWORD = 'your password' | |
from_name = ARGV[0] | |
from_email = ARGV[1] | |
to_name = ARGV[2] | |
to_email = ARGV[3] | |
subject = ARGV[4] | |
body = ARGV[5] | |
msg = <<EOF | |
From: #{from_name} <#{from_email}> | |
To: #{to_name} <#{to_email}> | |
Subject: #{subject} | |
#{body} | |
EOF | |
Net::SMTP.start( $SERVER, $PORT, $DOMAIN, $USERNAME, $PASSWORD, :plain ) do |smtp| | |
smtp.sendmail msg, from_email, to_email | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment