フォーチュンサモナーズ
«前の日記(2005-12-03) 最新 次の日記(2005-12-11)» 編集

Don'tStopMusic

2003|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|12|
2006|01|02|03|04|05|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|08|

カテゴリ別 2003年 | 2004年 | 2005年 | 2006年 | 2007年 | 2008年

知り合いサイト: よんだもの / 暴想 / Linuxでやる夫 / 新宿Vipper / 僕だけが幸せになればいいのに。


2005-12-08

_ [Ruby] tmail でメール送信 このエントリーを含むブックマーク

Ruby勉強記 - mail処理

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
本日のTrackBacks(全1件) []
_ Fifth-Season:[Ruby] Ruby勉強記 - Ruby でメール (2005-12-11 11:57)

[http://dontstopmusic.no-ip.org/diary/20051208.html#p01:title=tmail でメール送信]>> MIME::Lite::TT::Japanese ほど手軽ではありませんが tmail を使うとメールの作成は簡単です。文字コード変換には NKF、あとは必要に応じてテンプレートに erb を使ったりし..


最近のコメント:

  1. n (12-19)
  2. だて (12-17)
  3. k田 (12-17)

RSS
Creative Commons License
This work is licensed under a Creative Commons License
(note: text only. w/o web design, citations, (re)distributed softwares).