Skip to content

Instantly share code, notes, and snippets.

@koseki
Created March 27, 2009 16:59
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save koseki/86778 to your computer and use it in GitHub Desktop.
Save koseki/86778 to your computer and use it in GitHub Desktop.
rubyで日本語のメール送信
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