2007年12月9日日曜日

【Ruby de Mailer】送信出来たよ

smtpでの送信が出来た。例にならってクラス化しました。
ついでに、MessegeBoxモジュール作成。エラー捕捉に使ってみた。
-----
require 'Win32API'
require 'net/smtp'

module Msg
 def info(message)
  messagebox = Win32API.new('user32', 'MessageBox', %w(p p p i), 'i')
  messagebox.call(0, message, 'Info', 0)
 end
end
class Send
 include Msg
 def send(to, subject, content)
  Net::POP3.auth_only( "#{$pop3_server}", "#{$pop3_port}", "#{$user}", "#{$passwd}" )
  Net::SMTP.start( "#{$smtp_server}", "#{$smtp_port}", "localhost.localdomain", "#{$user}", "#{$passwd}", :plain ) {|smtp|
    smtp.ready( "#{$address}", "#{to}" ) {|f|
      f.puts "From: #{$address}"
      f.puts "To: #{to}"
      f.puts "Subject: #{subject}"
      f.puts
      f.puts "#{content}"
    }
  }
 rescue => error
  info(error)
  exit(1)
 end
end
-----

処理的には、POP Before SMTPでやってみた感じ。
自分の使ってるメールサーバがPOP Before SMTPだから。。。

GUIはやっぱりvrubyになりそうな感じ。
難しいなぁ・・・と思う今日この頃。

0 件のコメント: