カテゴリ別 2003年 | 2004年 | 2005年 | 2006年 | 2007年 | 2008年
知り合いサイト: よんだもの / 暴想 / Linuxでやる夫 / 新宿Vipper / 僕だけが幸せになればいいのに。
Rubyでメールを送るときの処理を検索してもなかなかエレガントなのが見つからない。
MIME::Lite::TT::Japanese ほど手軽ではありませんが tmail を使うとメールの作成は簡単です。文字コード変換には NKF、あとは必要に応じてテンプレートに erb を使ったりしています。
require 'net/smtp'
require 'nkf'
require 'tmail'
mail = TMail::Mail.new
mail.to = ['receiver01@example.com', 'receiver02@example.com']
mail.cc = ['receiver03@example.com']
mail.bcc = ['receiver04@example.com']
mail.from = 'sender@example.com'
mail.subject = NKF.nkf('-j -m0', "件名")
mail.date = Time.now
mail.mime_version = '1.0'
mail.set_content_type('text', 'plain', {'charset' => iso-2022-jp'})
mail.encoding = '7bit'
mail.body = NKF.nkf('-j -m0', "本文")
Net::SMTP.start('smtp.example.com', 25) do |smtp|
str = mail.encoded
smtp.send_mail(str, mail.from_address, mail.destinations)
end
[http://dontstopmusic.no-ip.org/diary/20051208.html#p01:title=tmail でメール送信]>> MIME::Lite::TT::Japanese ほど手軽ではありませんが tmail を使うとメールの作成は簡単です。文字コード変換には NKF、あとは必要に応じてテンプレートに erb を使ったりし..
最近のコメント:
RSS
![]()
This work is licensed under a
Creative Commons License
(note: text only. w/o web design, citations, (re)distributed softwares).