Created
March 19, 2009 17:04
-
-
Save repeatedly/81938 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env ruby1.9 | |
| # -*- coding: utf-8 -*- | |
| require 'csv' | |
| require 'erb' | |
| require 'kconv' | |
| require 'net/smtp' | |
| require 'openssl' | |
| def post(content, config) | |
| smtpserver = Net::SMTP.new(config[:smtp], config[:port]) | |
| if config[:tls] | |
| if RUBY_VERSION < '1.9.0' | |
| smtpserver.enable_tls(OpenSSL::SSL::VERIFY_NONE) | |
| else | |
| #context = OpenSSL::SSL::SSLContext.new | |
| #context.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
| #smtpserver.enable_tls(nil) | |
| smtpserver.enable_tls | |
| end | |
| end | |
| message = "" | |
| message << "From: TPF <#{config[:mail]}>\n" | |
| message << "To: #{config[:to]}\n" | |
| message << "Subject: #{config[:title]}\n" | |
| message << "\n" | |
| message << content + "\n" | |
| smtpserver.start(config[:helo], config[:id], config[:pass], :login) { |smtp| | |
| #smtp.send_message(message.kconv(Kconv::JIS, Kconv::UTF8), config[:mail], config[:to]) | |
| smtp.send_message(message, config[:mail], config[:to]) | |
| } | |
| end | |
| body = File.read('body.txt') | |
| car_ = File.read('car.txt') | |
| config = { | |
| :id => '[email protected]', | |
| :pass => 'foobarbaz', | |
| :smtp => 'smtp.gmail.com', | |
| :helo => 'gmail.com', | |
| :port => 465, | |
| :mail => '[email protected]', | |
| :title => 'Title', | |
| :tls => true | |
| } | |
| no = 1 | |
| CSV.foreach(ARGV.shift) do |row| | |
| car = '' | |
| erb = ERB.new(body) | |
| name = row[1].force_encoding('utf-8') | |
| config[:to] = row[2].force_encoding('utf-8') | |
| if row[6].force_encoding('utf-8') == 'はい' | |
| car = car_ | |
| end | |
| post(erb.result(binding), config) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment