Skip to content

Instantly share code, notes, and snippets.

@codebutler
Created January 27, 2011 04:21
Show Gist options
  • Select an option

  • Save codebutler/798059 to your computer and use it in GitHub Desktop.

Select an option

Save codebutler/798059 to your computer and use it in GitHub Desktop.
declare gmail inbox bankruptcy
require 'rubygems'
require 'gmail'
require 'gmail_xoauth'
NAME = "Eric Butler"
EMAIL = 'eric@codebutler.com'
TOKEN = 'CHANGEME'
TOKEN_SECRET = 'CHANGEME'
CONSUMER_KEY = 'anonymous'
CONSUMER_SECRET = 'anonymous'
module Gmail
class Client
def smtp_settings
[ :smtp, {
:address => 'smtp.gmail.com',
:port => 587,
:enable_starttls_auto => true,
:authentication => :xoauth,
:user_name => EMAIL,
:password => {
:consumer_key => CONSUMER_KEY,
:consumer_secret => CONSUMER_SECRET,
:token => TOKEN,
:token_secret => TOKEN_SECRET
}
}]
end
end
end
Gmail.connect(EMAIL, TOKEN, TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET) do |gmail|
count = gmail.inbox.emails(:all).count
current = 0
puts "Total messages: #{count}"
gmail.inbox.emails(:all) do |email|
from_address = "#{email.envelope.from.first.mailbox}@#{email.envelope.from.first.host}"
gmail.deliver! do
from "#{NAME} <#{EMAIL}>"
to from_address
subject "RE: #{email.envelope.subject}"
text_part do
body <<-EOF
Hi!
Unfortunately I have so much unread email that I've decided to declare Inbox bankruptcy and start over.
If you still need to reach me, please send a new message.
If you have a question about Firesheep, please post to the discussion group instead.
https://groups.google.com/forum/#!forum/firesheep
Sorry and thanks,
- Eric
EOF
end
in_reply_to email.envelope.message_id
references email.envelope.message_id
end
email.archive!
current += 1
puts "Mail sent to #{from_address} [#{current}/#{count}]"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment