Rubyスクリプトからメール
上で触れたスクリプトの中身は次のようなもの.今回はlocalhostのPostfixに送っただけなので楽だったが,今どきだとSMTP over SSLが必須な場合もあるだろう.そういう場合の対処はよく知らない.
#! /usr/bin/ruby -Ke require 'tmail' require 'net/smtp' require 'kconv' mail_from = 'sender@example.com' mail_to = 'receiver@example.com' $smtp_server = 'localhost' mail = TMail::Mail.new mail.from = "送り主 <#{mail_from}>" mail.to = "受け取り人 <#{mail_to}>" mail.subject = '主題' mail.date = Time.now mail.mime_version = '1.0' mail.set_content_type('text', 'plain', {'charset' => 'iso-2022-jp'}) mail.transfer_encoding = '8bit' org_body = <e print "SMTP Error occured: " p e end