Last active
August 29, 2015 14:19
-
-
Save jwo/7da6f943cc7c5c62ed68 to your computer and use it in GitHub Desktop.
Wanted to send about 15 emails to people, but I didn't want to BCC people. Also I didn't want to send 15 emails bc UGH. So I used the power of 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
source "https://rubygems.org" | |
gem 'pony' | |
gem 'dotenv' |
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 'bundler' | |
Bundler.require | |
require 'csv' | |
require 'erb' | |
Dotenv.load | |
gmail_username = ENV.fetch("GMAIL_USERNAME") | |
gmail_password = ENV.fetch("GMAIL_PASSWORD") | |
erb = ERB.new(File.read("mass_mail.text.erb")) | |
CSV.foreach('contacts.csv', headers: true) do |row| | |
data = row.to_hash | |
email = data.fetch('email') | |
first_name = data.fetch('first_name') | |
b = binding | |
Pony.mail({ | |
:to => email, | |
:subject => "Thanks for being awesome", | |
:body => erb.result(b), | |
:via => :smtp, | |
:via_options => { | |
:address => 'smtp.gmail.com', | |
:port => '587', | |
:enable_starttls_auto => true, | |
:user_name => gmail_username, | |
:password => gmail_password, | |
:authentication => :plain, # :plain, :login, :cram_md5, no auth by default | |
:domain => "localhost.localdomain" # the HELO domain provided by the client to the server | |
} | |
}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment