{"id":413,"date":"2008-05-02T13:00:16","date_gmt":"2008-05-02T04:00:16","guid":{"rendered":"http:\/\/www.javable.jp\/blog\/?p=413"},"modified":"2012-04-17T14:51:29","modified_gmt":"2012-04-17T05:51:29","slug":"ruby%e8%a6%9a%e6%9b%b8","status":"publish","type":"post","link":"https:\/\/www.javable.jp\/blog\/413.html","title":{"rendered":"Ruby\u899a\u66f8"},"content":{"rendered":"<p>\u73cd\u3057\u304fRuby\u3067CGI\u306a\u3093\u305e\u4f5c\u3063\u305f\u306e\u3067\u3001\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u30e1\u30e2\u3092\u2026<\/p>\r\n<h4>CGI\u304b\u3089\u30e1\u30fc\u30eb\u3092\u9001\u308b<\/h4>\r\n<p>Ruby\u306b\u306f TMail \u3068\u304b ActionMailer \u306a\u3069\u306e\u30e1\u30fc\u30eb\u9001\u4fe1\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u3042\u308b\u3088\u3046\u3067\u3059\u304c\u3001\u8a66\u3057\u3066\u307f\u305f\u3068\u3053\u308d\u3001\u305d\u3082\u305d\u3082\u914d\u5099\u5bfe\u8c61\u306e\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u30fc\u304b\u3089\u306fSMTP\u3067\u306e\u9001\u4fe1\u304c\u51fa\u6765\u307e\u305b\u3093\u3067\u3057\u305f\u3002\r\n\u30dd\u30fc\u30c8\u304c\u9589\u3058\u3089\u308c\u3066\u308b\u3089\u3057\u3044\u3002\u3002\u3002<\/p>\r\n<p>\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u30fc\u306e\u8aac\u660e\u66f8\u3092\u8aad\u3080\u3068 sendmail \u306f\u4f7f\u3048\u308b\u3088\u3046\u3060\u3063\u305f\u306e\u3067\u3001\u305d\u3044\u3064\u3067\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308b\u3068\u3046\u307e\u304f\u884c\u304d\u307e\u3057\u305f\u3002\r\n\u4e0b\u8a18\u304c\u305d\u306e\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<\/p>\r\n<pre class=\"code_list\">require 'kconv'\r\n\r\ndef sendmail(from, to, cc, bcc, subject, body)\r\n  \r\n  path = &quot;\/usr\/lib\/sendmail&quot; # sendmail\u306e\u30d1\u30b9\r\n  subject = subject.tojis\r\n  subject = [subject].pack('m') # Base64\r\n  subject.gsub!(\/\\n\/, &quot;&quot;)\r\n  subject = &quot;=?ISO-2022-JP?B?#{subject}?=&quot;\r\n  body = body.tojis\r\n\r\n  IO.popen(&quot;#{path} -t&quot;, &quot;r+&quot;) { |io|\r\n    io.print &quot;From: #{from}\\n&quot;\r\n    io.print &quot;To: #{to}\\n&quot;\r\n    io.print &quot;Cc: #{cc}\\n&quot; if cc != nil\r\n    io.print &quot;Bcc: #{bcc}\\n&quot; if bcc != nil\r\n    io.print &quot;Subject: #{subject}\\n&quot;\r\n    io.print &quot;MIME-Version: 1.0\\n&quot;\r\n    io.print &quot;Content-Type: text\/plain; charset=iso-2022-jp\\n&quot;\r\n    io.print &quot;Content-Transfer-Encoding: 7bit\\n&quot;\r\n    io.print &quot;\\n&quot;\r\n    io.print &quot;#{body}\\n&quot;\r\n  }\r\nend<\/pre>\r\n\r\n<h4>JIS\u5909\u63db\u3067\u6587\u5b57\u5316\u3051<\/h4>\r\n<p>\u524d\u8ff0\u306e\u30e1\u30fc\u30eb\u9001\u4fe1\u3067\u3001\u4ef6\u540d\u3092JIS\u306b\u5909\u63db\u3057\u3066\u307e\u3059\u304c\u3001\u30c6\u30b9\u30c8\u3057\u3066\u305f\u3089\u3053\u3053\u3067\u5fae\u5999\u306b\u6587\u5b57\u5316\u3051\u304c\u767a\u751f\u3057\u3066\u307e\u3057\u305f\u3002\r\n\u8abf\u3079\u3066\u307f\u308b\u3068\u3069\u3046\u3082\u4ef6\u540d\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u6587\u5b57\u30b3\u30fc\u30c9\u304cShift_JIS\u306a\u306e\u306b\u3001\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u6307\u5b9a\u305b\u305a\u306b Ruby \u306e\u30a4\u30f3\u30bf\u30d7\u30ea\u30bf\u3092\u5b9f\u884c\u3057\u3066\u3044\u305f\u306e\u304c\u539f\u56e0\u3089\u3057\u3044\u3002\u8aac\u660e\u306f\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u30de\u30cb\u30e5\u30a2\u30eb\u306b\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\r\n<p><a href=\"http:\/\/www.ruby-lang.org\/ja\/man\/html\/FAQ_C6FCCBDCB8ECA4CEBCE8A4EAB0B7A4A4.html#a10.2e1.20.b4.c1.bb.fa.a4.f2.b4.de.a4.f3.a4.c0.a5.b9.a5.af.a5.ea.a5.d7.a5.c8.a4.ac.ca.b8.bb.fa.b2.bd.a4.b1.a4.f2.bd.d0.ce.cf.a4.b7.a4.bf.a4.ea.a1.a2.c0.b5.a4.b7.a4.af.bc.c2.b9.d4.a4.c7.a4.ad.a4.ca.a4.a4.be.ec.b9.e7.a4.ac.a4.a2.a4.ea.a4.de.a4.b9\" rel=\"nofollow\">FAQ::\u65e5\u672c\u8a9e\u306e\u53d6\u308a\u6271\u3044 &#8211; Ruby\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u30de\u30cb\u30e5\u30a2\u30eb<\/a><\/p>\r\n<p>\u3053\u3046\u3059\u308c\u3070\u826f\u3044\u3093\u3067\u3059\u306d\u3002<\/p>\r\n<pre class=\"code_list\">#!\/usr\/local\/bin\/ruby -Ks<\/pre>\r\n\r\n<h4>CGI\u5b9f\u884c\u6642\u306b\u767a\u751f\u3057\u305f\u30a8\u30e9\u30fc\u3092\u898b\u308b<\/h4>\r\n<p>begin \uff5e rescue\uff08\u4f8b\u5916\u51e6\u7406\uff09end\r\n\u3067\u3001\u4f8b\u5916\u51e6\u7406\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3055\u305b\u308b\u3068\u3001\u4f8b\u5916\u767a\u751f\u6642\u306b\u30d0\u30c3\u30af\u30c8\u30ec\u30fc\u30b9\u304c\u898b\u308c\u307e\u3057\u305f\u3002<\/p>\r\n<pre class=\"code_list\">require &quot;cgi&quot;\r\nrequire &quot;erb&quot;\r\n# \u540c\u4e00\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306erb\u30d5\u30a1\u30a4\u30eb\u3092\u53c2\u7167\r\nDir.glob(&quot;*.rb&quot;).each do |file|\r\n  require file\r\nend\r\n\r\nbegin\r\n\r\nprint &quot;Content-type: text\/html\\n\\n&quot;\r\ncgi = CGI.new\r\n# \u4ee5\u4e0b\u3001CGI\u306e\u51e6\u7406...\r\n\r\nrescue Exception =&gt; e #\u4f8b\u5916\u3092\u53d6\u5f97\r\n  print &quot;Content-Type: text\/plain\\n\\n&quot;\r\n  puts &quot;Error:&quot;\r\n  puts e\r\n  puts &quot;&quot;\r\n  puts &quot;backtrace:&quot;\r\n  print e.backtrace\r\nend<\/pre>","protected":false},"excerpt":{"rendered":"\u73cd\u3057\u304fRuby\u3067CGI\u306a\u3093\u305e\u4f5c\u3063\u305f\u306e\u3067\u3001\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u30e1\u30e2\u3092\u2026 CGI\u304b\u3089\u30e1\u30fc\u30eb\u3092\u9001\u308b Ruby\u306b\u306f TMail \u3068\u304b ActionMailer \u306a\u3069\u306e\u30e1\u30fc\u30eb\u9001\u4fe1\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u3042\u308b\u3088\u3046\u3067\u3059\u304c\u3001\u8a66\u3057\u3066\u307f\u305f\u3068\u3053\u308d\u3001\u305d\u3082\u305d\u3082\u914d\u5099 [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-413","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.javable.jp\/blog\/wp-json\/wp\/v2\/posts\/413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javable.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javable.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javable.jp\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javable.jp\/blog\/wp-json\/wp\/v2\/comments?post=413"}],"version-history":[{"count":3,"href":"https:\/\/www.javable.jp\/blog\/wp-json\/wp\/v2\/posts\/413\/revisions"}],"predecessor-version":[{"id":416,"href":"https:\/\/www.javable.jp\/blog\/wp-json\/wp\/v2\/posts\/413\/revisions\/416"}],"wp:attachment":[{"href":"https:\/\/www.javable.jp\/blog\/wp-json\/wp\/v2\/media?parent=413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javable.jp\/blog\/wp-json\/wp\/v2\/categories?post=413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javable.jp\/blog\/wp-json\/wp\/v2\/tags?post=413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}