Skip to content

Instantly share code, notes, and snippets.

@khamanaka
Forked from snaka/sendmail.rb
Created March 15, 2010 14:39
Show Gist options
  • Save khamanaka/332888 to your computer and use it in GitHub Desktop.
Save khamanaka/332888 to your computer and use it in GitHub Desktop.
バッチの実行結果をGmailでメール送信するrubyスクリプト
# USAGE:
# echo "ほげ" | ruby send-gmail.rb
#
require 'rubygems'
require 'kconv'
require 'tmail'
require "tlsmail"
mail = TMail::Mail.new
mail.to = '[email protected]'
mail.from = '[email protected]'
mail.subject = "Batch program report"
mail.date = Time.now
mail.mime_version = '1.0'
mail.set_content_type 'text', 'plain', {'charset'=>'iso-2022-jp'}
mail.body =<<EOM
#{STDIN.read.tojis}
--
from Batch program at #{Time.now.strftime "%Y年%m月%d日 %H時%M分%S秒"}
EOM
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
Net::SMTP.start( "smtp.gmail.com", 587, "localhost.localdomain", "[email protected]", "password", "plain"){ |smtp|
smtp.sendmail(mail.encoded, mail.from, mail.to)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment