Skip to content

Instantly share code, notes, and snippets.

@guilhermewop
Forked from max/mailer.rb
Created March 23, 2020 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilhermewop/4d3345689f7f4c9af69e8274e12b5fe1 to your computer and use it in GitHub Desktop.
Save guilhermewop/4d3345689f7f4c9af69e8274e12b5fe1 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@example.com>'
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