Skip to content

Instantly share code, notes, and snippets.

@3dd13
Created February 6, 2014 18:09
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 3dd13/8849483 to your computer and use it in GitHub Desktop.
Save 3dd13/8849483 to your computer and use it in GitHub Desktop.
snippet to read your gmail emails by label
require 'gmail'
require 'dotenv'
Dotenv.load
label_name = "" # label name here
Gmail.new(ENV["GMAIL_USERNAME"], ENV["GMAIL_PASSWORD"]) do |gmail|
mail_with_label = gmail.label(label_name)
count = mail_with_label.count
puts "Number of email for the label #{label_name}: #{count}"
first_email = mail_with_label.emails.first
puts "first_email: #{first_email.class}"
puts "first_email: #{first_email.send(:message).text_part}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment