Skip to content

Instantly share code, notes, and snippets.

@toshiharu
Created March 20, 2013 07:12
Show Gist options
  • Save toshiharu/5202860 to your computer and use it in GitHub Desktop.
Save toshiharu/5202860 to your computer and use it in GitHub Desktop.
Ruby 1.9/2.0 で Gmail へメールを送る。Ruby 1.8 で必要だった tlsmail.rb はいらないことを知った。
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
require 'rubygems'
require 'net/smtp'
from_addr = 'from@example.com'
to_addr = 'to@example.com'
message = <<EOM
From: #{from_addr}
To: #{to_addr}
Subject: test
test
EOM
smtpserver = Net::SMTP.new('smtp.gmail.com', 587)
smtpserver.enable_starttls
smtpserver.start('localhost.localdomain', ユーザ名, パスワード, :plain) { |smtp|
smtp.send_message message, from_addr, to_addr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment