Created
March 27, 2009 16:59
-
-
Save koseki/86778 to your computer and use it in GitHub Desktop.
rubyで日本語のメール送信
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "nkf" | |
require "net/smtp" | |
def sendmail(host, port, from, to, subject, body) | |
body = <<EOT | |
From: #{from} | |
To: #{to.to_a.join(",")} | |
Subject: =?ISO-2022-JP?B?#{NKF.nkf("-jMB", subject)}?= | |
Date: #{Time::now.strftime("%a, %d %b %Y %X %z")} | |
Mime-Version: 1.0 | |
Content-Type: text/plain; charset=ISO-2022-JP | |
Content-Transfer-Encoding: 7bit | |
#{NKF.nkf("-jm0", body)} | |
EOT | |
Net::SMTP.start(host, port) do |smtp| | |
smtp.send_mail body, from, to | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment