Class: Skutil::Mail
- Inherits:
-
Object
- Object
- Skutil::Mail
- Defined in:
- lib/skutil.rb
Class Method Summary collapse
- .create_addr_and_header(addr_data) ⇒ Object
- .send(from, to, title, body, smtp_addr = '127.0.0.1', smtp_port = 25) ⇒ Object
- .send_error(from, to, title, error, smtp_addr = '127.0.0.1', smtp_port = 25) ⇒ Object
Class Method Details
.create_addr_and_header(addr_data) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/skutil.rb', line 93 def self.create_addr_and_header(addr_data) addr = '' addr_4_header = '' case addr_data.class.to_s when 'String' addr = addr_data.dup addr_4_header = addr.dup when 'Array' addr = addr_data[1].dup addr_4_header = addr_data[0].dup addr_4_header = Kconv.tojis(addr_4_header) addr_4_header = addr_4_header.split(//,1).pack('m'); addr_4_header = addr_4_header.chomp addr_4_header = "=?ISO-2022-JP?B?#{addr_4_header}?=<#{addr}>" else # TODO exception raise 'addr_data must be String or Array' end return addr,addr_4_header end |
.send(from, to, title, body, smtp_addr = '127.0.0.1', smtp_port = 25) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/skutil.rb', line 57 def self.send(from,to,title,body,smtp_addr='127.0.0.1',smtp_port=25) from_addr,from_addr_4_header = create_addr_and_header(from) title = Kconv.tojis(title) title = title.split(//,1).pack('m'); title = title.chomp if to.class.to_s == 'Array' tomany = to.join(',') else tomany = to.to_s; end head = <<HEAD Subject: =?ISO-2022-JP?B?#{title}?= To: #{tomany} From: #{from_addr_4_header} Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: Text/Plain; charset=iso-2022-jp HEAD src = head + "\n" + Kconv.tojis(body) # puts src m = Net::SMTPSession.new(smtp_addr, smtp_port) m.start() m.sendmail(src, from_addr, to) m.finish end |
.send_error(from, to, title, error, smtp_addr = '127.0.0.1', smtp_port = 25) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/skutil.rb', line 83 def self.send_error(from,to,title,error,smtp_addr='127.0.0.1',smtp_port=25) body = <<-BODY #{error.to_s} #{error.backtrace.join("\n")} ===================================== #{Skutil::Server.environment} BODY Skutil::Mail.send(from,to,title,body,smtp_addr,smtp_port) end |