Create a gist now

Instantly share code, notes, and snippets.

Embed
Tiny script for sending bulk emails via Gmail.
# Dependencies: `gem install ruby-gmail`
require 'gmail'
require 'csv'
email_subject = "subject line"
email_body = File.open("email.txt", "rb").read
username = "username"
password = "password"
gmail = Gmail.new(username, password)
addresses = []
# contacts.csv exported from Gmail contacts
CSV.foreach('contacts.csv') do |row|
addresses.push(row[14])
end
# Remove header
addresses.shift
addresses.each() { |address|
email = gmail.generate_message do
to address
from "Your Name <you@email.com>"
subject email_subject
body email_body
end
gmail.deliver(email)
}
gmail.logout
@lkuper

This comment has been minimized.

Show comment
Hide comment
@lkuper

lkuper Aug 8, 2016

The "Your Name <you@email.com>" part isn't actually necessary, because ruby-gmail pulls the you@email.com from your account. If you want the Your Name to show up, though, you have to put it in manually like I did here (or, at least, I couldn't find an easy way to make ruby-gmail do it in a few minutes of looking).

Owner

lkuper commented Aug 8, 2016

The "Your Name <you@email.com>" part isn't actually necessary, because ruby-gmail pulls the you@email.com from your account. If you want the Your Name to show up, though, you have to put it in manually like I did here (or, at least, I couldn't find an easy way to make ruby-gmail do it in a few minutes of looking).

@lkuper

This comment has been minimized.

Show comment
Hide comment
@lkuper

lkuper Aug 8, 2016

Oh, and I never close the open file handle. YOLO.

Owner

lkuper commented Aug 8, 2016

Oh, and I never close the open file handle. YOLO.

@luilver

This comment has been minimized.

Show comment
Hide comment
@luilver

luilver Apr 12, 2018

I'm getting this error: -> "534 5.7.14 https://support.google.com/mail/answer/78754 x68sm2113801ede.25 - gsmtp\r\n"
/home/****/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/net/smtp.rb:976:in `check_auth_response': 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbto (Net::SMTPAuthenticationError)

I actually configured Gmail to allow less secure apps, but still having the same issue.

luilver commented Apr 12, 2018

I'm getting this error: -> "534 5.7.14 https://support.google.com/mail/answer/78754 x68sm2113801ede.25 - gsmtp\r\n"
/home/****/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/net/smtp.rb:976:in `check_auth_response': 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbto (Net::SMTPAuthenticationError)

I actually configured Gmail to allow less secure apps, but still having the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment