-
-
Save reynaldobarrosjr/39361fdbcb894c7a9e3ca753d7178003 to your computer and use it in GitHub Desktop.
A simple Ruby script to send mass emails
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
| 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