Skip to content

Instantly share code, notes, and snippets.

@yeban
Created April 11, 2010 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yeban/362842 to your computer and use it in GitHub Desktop.
Save yeban/362842 to your computer and use it in GitHub Desktop.
Bare bones Ruby script to send emails using Gmail
=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