-
-
Save khamanaka/332888 to your computer and use it in GitHub Desktop.
バッチの実行結果をGmailでメール送信するrubyスクリプト
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
# 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