Skip to content

Instantly share code, notes, and snippets.

@max
Last active March 23, 2020 16:44
Show Gist options
  • Save max/245d77b45aa7084bfa6f to your computer and use it in GitHub Desktop.
Save max/245d77b45aa7084bfa6f 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