Skip to content

Instantly share code, notes, and snippets.

@reynaldobarrosjr
Forked from max/mailer.rb
Created September 20, 2017 17:25
Show Gist options
  • Select an option

  • Save reynaldobarrosjr/39361fdbcb894c7a9e3ca753d7178003 to your computer and use it in GitHub Desktop.

Select an option

Save reynaldobarrosjr/39361fdbcb894c7a9e3ca753d7178003 to your computer and use it in GitHub Desktop.
A simple Ruby script to send mass emails
require 'mail'
require 'csv'
FILE = ARGV[0]
Mail.defaults do
delivery_method :smtp, {
address: '',
port: 587,
domain: '',
user_name: '',
password: ENV.fetch('EMAIL_PASSWORD'),
authentication: :plain,
enable_starttls_auto: true
}
end
def send_email(address)
mail = Mail.new do
to address
from 'Example <[email protected]>'
subject ''
body generate_body
end
end
def generate_body
%Q(
Dear User,
...
)
end
CSV.parse(File.read(FILE)).each do |line|
address = line[0]
m = send_email(address)
puts m.to_s
p m.deliver!
puts
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment