-
-
Save brijeshgpt7/2fca49d0fa87993d78b331b74d704f99 to your computer and use it in GitHub Desktop.
Bare bones Ruby script to send emails using Gmail
This file contains hidden or 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