Code Monkey home page Code Monkey logo

ruby-gmail's Introduction

Notice

I have pushed verion 0.3.1 to rubygems.org (Yay, thanks Nick Quaranto for the help) which is a build straight from master.

Second, this gem is getting back on track. See this issue here for more information.

ruby-gmail

Author(s)

  • Daniel Parker of BehindLogic.com
  • Nathan Herald

Extra thanks for specific feature contributions from:

Description

A Rubyesque interface to Gmail, with all the tools you'll need. Search, read and send multipart emails; archive, mark as read/unread, delete emails; and manage labels.

Features

  • Search emails
  • Read emails (handles attachments)
  • Emails: Label, archive, delete, mark as read/unread/spam
  • Create and delete labels
  • Create and send multipart email messages in plaintext and/or html, with inline images and attachments
  • Utilizes Gmail's IMAP & SMTP, MIME-type detection and parses and generates MIME properly.

Problems:

  • May not correctly read malformed MIME messages. This could possibly be corrected by having IMAP parse the MIME structure.
  • Cannot grab the plain or html message without also grabbing attachments. It might be nice to lazy-[down]load attachments.

Example Code:

1) Require gmail

require 'gmail'

2) Start an authenticated gmail session

#    If you pass a block, the session will be passed into the block,
#    and the session will be logged out after the block is executed.
gmail = Gmail.new(username, password)
# ...do things...
gmail.logout

Gmail.new(username, password) do |gmail|
  # ...do things...
end

3) Count and gather emails!

# Get counts for messages in the inbox
gmail.inbox.count
gmail.inbox.count(:unread)
gmail.inbox.count(:read)

# Count with some criteria
gmail.inbox.count(:after => Date.parse("2010-02-20"), :before => Date.parse("2010-03-20"))
gmail.inbox.count(:on => Date.parse("2010-04-15"))
gmail.inbox.count(:from => "[email protected]")
gmail.inbox.count(:to => "[email protected]")

# Combine flags and options
gmail.inbox.count(:unread, :from => "[email protected]")

# Labels work the same way as inbox
gmail.mailbox('Urgent').count

# Getting messages works the same way as counting: optional flag, and optional arguments
# Remember that every message in a conversation/thread will come as a separate message.
gmail.inbox.emails(:unread, :before => Date.parse("2010-04-20"), :from => "[email protected]")

# Search the same way you do on Gmail's web interface:
gmail.inbox.emails(gm: 'before:2010-02-20 after:2010-03-20')
gmail.inbox.emails(gm: 'on:2010-04-15')
gmail.inbox.emails(gm: 'from:[email protected]')
gmail.inbox.emails(gm: 'to:[email protected]')
gmail.inbox.emails(gm: 'is:read from:[email protected] "you are a great employee"')

# Get messages without marking them as read on the server.
gmail.peek = true
gmail.inbox.emails(:unread, :before => Date.parse("2010-04-20"), :from => "[email protected]")

4) Work with emails!

# any news older than 4-20, mark as read and archive it...
gmail.inbox.emails(:before => Date.parse("2010-04-20"), :from => "[email protected]").each do |email|
  email.mark(:read) # can also mark :unread or :spam
  email.archive!
end

# delete emails from X...
gmail.inbox.emails(:from => "x-fiancé@gmail.com").each do |email|
  email.delete!
end

# Save all attachments in the "Faxes" label to a folder
folder = "/where/ever"
gmail.mailbox("Faxes").emails.each do |email|
  email.attachments.each do |attachment|
    file = File.new(folder + attachment.filename, "w+")
    file << attachment.decoded
    file.close
  end
end

# Add a label to a message
email.label("Faxes")

# Or "move" the message to a label
email.move_to("Faxes")

5) Create new emails!

Creating emails now uses the amazing Mail rubygem. See its documentation here. Ruby-gmail will automatically configure your Mail emails to be sent via your Gmail account's SMTP, so they will be in your Gmail's "Sent" folder. Also, no need to specify the "From" email either, because ruby-gmail will set it for you.

gmail.deliver do
  to "[email protected]"
  subject "Having fun in Puerto Rico!"
  text_part do
    body "Text of plaintext message."
  end
  html_part do
    content_type 'text/html; charset=UTF-8'
    body "<p>Text of <em>html</em> message.</p>"
  end
  add_file "/path/to/some_image.jpg"
end
# Or, generate the message first and send it later
email = gmail.generate_message do
  to "[email protected]"
  subject "Having fun in Puerto Rico!"
  body "Spent the day on the road..."
end
email.deliver!
# Or...
gmail.deliver(email)

Requirements

  • ruby
  • net/smtp
  • net/imap
  • tmail
  • shared-mime-info rubygem (for MIME-detection when attaching files)

Install

gem install ruby-gmail

License

(The MIT License)

Copyright (c) 2009 BehindLogic

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ruby-gmail's People

Contributors

adimircolen avatar aliceclv avatar amalhotra avatar astarr avatar elberskirch avatar fgalassi avatar gabrielengel avatar jamster avatar jasonwbarnett avatar joshaven avatar mikker avatar myobie avatar namxam avatar nimdraugsael avatar pict3 avatar refriedchicken avatar rtlong avatar scockram avatar wengzilla avatar ysaito8015 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ruby-gmail's Issues

uninitialized constant Gmail (NameError)

I just installed ruby-gmail via gem. I created a sample program, but I cant make it work. It just hangs up, when Gmal class is used. "uninitialized constant Gmail (NameError)"

The code is:
require 'rubygems'
require 'gmail'
gmail = Gmail.new(...etc

Platform:
Ubuntu, REE 1.8.6, ruby-gmail 0.0.8

Email without title

If there is an email without title in the inbox and I do that

emails = g.inbox.emails(:unread)
emails.each do |email|
subject=email.message.subject
end

in subject I don't found an empty string but a string with "From: ....."

generate_message is not supported

I followed the example found in the wiki 5) Create new emails!

email = gmail.generate_message do
  to "[email protected]"
  subject "Having fun in Puerto Rico!"
  body "Spent the day on the road..."
end

but I get the following error:
undefined method `generate_message' for #Gmail::Client::Plain:0x007f94813a5fa8 (NoMethodError)

Ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]
Mac OS X 10.7.5

IETF PARSING FAIL! (''A'' structure)

This is a wonderful gem. Thank you for your hard work!

I keep getting this error from certain emails:

IETF PARSING FAIL! (''A'' structure)

Shouldn't ruby-gmail be able to parse any email that Gmail can parse?

Seems like gmail.peek = true is a safer default

I realize this gem isn't actively developed at the moment, so this note is here as much for the maintainers as it is a reminder for myself.

It'd be nice to have the gem work without side effects by default

ie gmail.peek = true as a default setting.

If I get a chance to create a PR while working on my my own task, I'll do so.

Thanks for keeping an eye on this gem 👍 It's super helpful!

Attachments sent but not received

Using add_file, I have many recipients that are saying they did not receive the attached file. The attachment appears in the sent file on my gmail server. It appears that gmail accounts and certain other mail providers receive attachments fine, because when testing I did not encounter any problems. One recipient forwarded the email to another account and was able to open the attachment. Here is my code, perhaps someone can make sense of this.

require 'csv'
require 'gmail'

Gmail.new('email','password') do |gmail|
    CSV.foreach("/Users/teacher/Desktop/merge.csv") do |row|
        gmail.deliver do
            to row[5]
            subject "Report for #{row[1]} #{row[0]}"
            html_part do
                content_type 'text/html; charset=UTF-8'
                body "html body"
            end
            add_file row[4]
        end
    end
end

no such file to load -- mime/message

In my Gemfile:
gem "ruby-gmail", '0.2.1'
In console:
require 'gmail'
no such file to load -- mime/message
gems/ruby-gmail-0.2.1/lib/gmail/message.rb:1
...

Perhaps you forget to delete line "require 'mime/message'" in message.rb.

Segmentation fault when using mysql and rails3

Hi,

I always get a segmentation fault whenever I try to use ruby-gmail in my rails 3 application.

Here's my steps to generate the error:

rails new my_app -d mysql
cd my_app
echo "gem 'mime'\ngem 'ruby-gmail'" >> Gemfile
bundle install
rails console

In the console:

require 'mime/message'
require 'gmail'
gmail = Gmail.new('my_gmail_email','my_password')

This generates the following error (truncated):

/Users/michaelm/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/imap.rb:1397: [BUG] Segmentation fault

This is under Ruby 1.9.2-p0, Rails 3.0.4 and mysql2 gem 0.2.6.

It works fine under Rails 2.3. It also works fine when I change the database from mysql to sqlite.

Any ideas and how to get it working with mysql?

Thanks,

Michael.

Searching under a label does not appear to work

I'm using the 0.3.1 version of this gem and noticed that searching email under a label no longer works. For example:

after = Date.today - 15
count = gmail.mailbox('Label').count(:after => after, :subject => "Subject X")

This yields the count of ALL emails under the label instead of the number of emails with the search criteria.

Thread support

Hey, one of the great advantages of Gmail is threads... is there a way for a given message to retrieve th ethread?

Thanks!

undefined local variable or method `name' for #<Gmai

undefined local variable or method name' for #<Gmail:0x..fb6710230 ([email protected]) disconnected> /var/www/mts-tech/vendor/plugins/ruby-gmail/lib/gmail.rb:122:inin_label'
/var/www/mts-tech/vendor/plugins/ruby-gmail/lib/gmail.rb:38:in `inbox'

Line "mailboxes[name] ||= Mailbox.new(self, mailbox)"
Change to "mailboxes[mailbox.name] ||= Mailbox.new(self, mailbox)"

html_part example error

I had to add

content_type 'text/html; charset=UTF-8'

before the

   body "<p>Hello world</p>"

as in the README here: https://github.com/mikel/mail

Without that, it wouldn't recognise the html-ness of my email. Perhaps you could update the readme?

cheers

ArgumentError: wrong number of arguments (0 for 1) when calling Gmail.label

Version: 0.2.1

Title is hopefully self-explanatory. When calling Gmail.label with known good label, receive the following stack:

ArgumentError: wrong number of arguments (0 for 1)
from /usr/lib/ruby/gems/1.8/gems/ruby-gmail-0.2.1/lib/gmail.rb:53:in mailbox' from /usr/lib/ruby/gems/1.8/gems/ruby-gmail-0.2.1/lib/gmail.rb:53:inmailbox'

Thoughts?

Net::IMAP::BadResponseError

Hey, first thank you for your hard work,
I keep getting:

irb(main):006:0> gmail.inbox.emails(:after => '2009-03-04', :before => '2009-03-15')
Net::IMAP::BadResponseError: Unknown command i7if511808mue.17
from /usr/lib/ruby/1.8/net/imap.rb:985:in pick_up_tagged_response' from /usr/lib/ruby/1.8/net/imap.rb:976:inget_tagged_response'
from /usr/lib/ruby/1.8/net/imap.rb:1034:in send_command' from /usr/lib/ruby/1.8/monitor.rb:242:insynchronize'
from /usr/lib/ruby/1.8/net/imap.rb:1019:in send_command' from /usr/lib/ruby/1.8/net/imap.rb:398:inselect'
from /usr/lib/ruby/1.8/monitor.rb:242:in synchronize' from /usr/lib/ruby/1.8/net/imap.rb:396:inselect'
from /var/lib/gems/1.8/gems/ruby-gmail-0.0.6/lib/gmail.rb:60:in in_mailbox' from /var/lib/gems/1.8/gems/ruby-gmail-0.0.6/lib/gmail/mailbox.rb:56:inemails'
from (irb):6

530 5.7.0 Must issue a STARTTLS command first

My ruby version is 1.8.6, and my OS is Centos5.4 32bit
[root@domU-12-31-39-03-4A-54 ~]# gem list

*** LOCAL GEMS ***

activesupport (2.3.5)
log4r (1.1.7)
mail (2.2.1)
mime (0.1)
mime-types (1.16)
net-sftp (2.0.3)
net-ssh (2.0.15)
polyglot (0.3.1)
ruby-gmail (0.2.1)
shared-mime-info (0.1)
tlsmail (0.0.1)
tmail (1.2.7.1)
treetop (1.4.5)
xml-simple (1.0.12)

Error message while running my sample code.
Previosly I have install ruby-gamil ver 0.8 and it works but I get failed after ugrate to the latest version.
/usr/lib/ruby/gems/1.8/gems/tlsmail-0.0.1/lib/net/smtp.rb:679:in auth_plain': 530 5.7.0 Must issue a STARTTLS command first. w29sm21914057vcr.2 (Net::SMTPAuthenticationError) from /usr/lib/ruby/gems/1.8/gems/tlsmail-0.0.1/lib/net/smtp.rb:673:insend'
from /usr/lib/ruby/gems/1.8/gems/tlsmail-0.0.1/lib/net/smtp.rb:673:in authenticate' from /usr/lib/ruby/gems/1.8/gems/tlsmail-0.0.1/lib/net/smtp.rb:488:indo_start'
from /usr/lib/ruby/gems/1.8/gems/tlsmail-0.0.1/lib/net/smtp.rb:440:in start' from /usr/lib/ruby/gems/1.8/gems/mail-2.2.1/lib/mail/network/delivery_methods/smtp.rb:101:indeliver!'
from /usr/lib/ruby/gems/1.8/gems/mail-2.2.1/lib/mail/message.rb:238:in deliver!' from /usr/lib/ruby/gems/1.8/gems/ruby-gmail-0.2.1/lib/gmail.rb:85:indeliver'
from test.rb:19

Failure on initialization

Trying to use gem with Ruby 1.9.1.

g = Gmail.new(login, password)
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
    from /usr/local/lib/ruby/1.9/net/imap.rb:1320:in `connect'
    from /usr/local/lib/ruby/1.9/net/imap.rb:1320:in `start_tls_session'
    from /usr/local/lib/ruby/1.9/net/imap.rb:933:in `initialize'
    from /usr/home/taro/gems/gems/ruby-gmail-0.0.4/lib/gmail.rb:21:in `new'
    from /usr/home/taro/gems/gems/ruby-gmail-0.0.4/lib/gmail.rb:21:in `initialize'
    from (irb):1:in `new'
    from (irb):1
    from /usr/local/bin/irb19:12:in `<main>'

Please suggest solution.
Thanks

Send email example broken

Following the example in the readme, sending email fails when trying to set plain.content (or html.content) because the encoding is nil.

See lines #102 and #168 of mime/entity.rb - together, they end up sending nil.to_s.downcase, but nil does not have a downcase method.

Double authentication

Does this work with dual authentication? I tried both my regular password, and an app-specific password, but both gave me a GMail object with the state "disconnected".

no such file to load -- mime/message (MissingSourceFile)

Hi,

I installed the ruby-gmail gem via "gem install ruby-gmail". The required dependencies appeared to install fine, which were:

shared-mime-info-0.1
treetop-1.4.7
mail-2.2.1
ruby-gmail-0.2.1

The problem is when I try to run
require 'gmail'
I get the error "no such file to load -- mime/message". Is there another gem I need? Do I need other require statements before the require 'gmail'?

Cheers,
~Mat

Error saving attachment

Here is my code

  vmFolder = '/home/user/vm/'
  email = gmail.inbox.emails(:unread).first
  email.attachments[0].save_to_file(vmFolder)

Getting this error

/var/lib/gems/1.8/gems/mail-2.2.5/lib/mail/message.rb:1251:in `method_missing':
undefined method `save_to_file' for #<Mail::Part:0xb74e9c1c> (NoMethodError)

TMail dependency should be specified

Current gemspec does not say ruby-gmail depends on tmail, though it is used in lib/mime/entity_tmail.rb. This is problematic when an user doesn't have tmail in his/her environment yet. Something like
gem.add_dependency 'tmail'
should be added to the Rakefile.

Invalid credentials on University ID

I was can login using one of my normal gmail accounts but I could not with my @rit.edu email. Although it does not look like it RIT uses gmail. I know that the problem is that the part after the user mail

meta.username = username =~ /@/ ? username : username + '@gmail.com'

Is there a way to possibly pass in an optional parameter for the part after the @ or allow people to pass in their entire email?

Lack of clear documentation regarding reading messages.

Hello, Im still trying to read a message from within the inbox. I have connected to the server, found the list of messages, but am unsure what method I should be using to actually view the body of the message.

Using:
gmail.inbox.emails(:unread, :from => mailaddress).each do |email|
email.message
Popped the error "undefined method: message"
This pops up for .read, .body.. etc Am I doing it wrong?

Not seeing attachments

Hi -- great work so far -- but I can't see attachments -- here's my program:

require 'rubygems'
require 'gmail'
gmail = Gmail.new('xxxxx', 'xxxxx') do |g|
  unread_count=g.inbox.count(:unread)
  print "There are " + g.inbox.count.to_s + " emails (" + unread_count.to_s + " unread).\n"
  counter=1
  g.inbox.emails(:unread).each do |msg|
  print "#{counter}/#{msg.message.from}/#{msg.message.subject}/#{msg.message.attachments.length.to_s} attachment(s)\n"
    msg.message.save_attachments_to("/home/mmcgrath/mail-puller/output")
    counter+=1
  end
end

There are four unread messages in the Inbox, three of which have attachments -- the script sees them correctly (i.e. Subject, From etc) but in all cases the attachments array is empty. Any thoughts?

i18n support

Message#archive! does not work in other languages because "All Mail" is hardcoded in message.rb. "Spam" can potentially change too from one language to another.

For example, in Italian while "Spam" is still "Spam", the "All Mail" mailbox is called "Tutti i messaggi"

Mailing list

Do you have mailing list for this project? Posting question here is wrong way. If you have mailing list, can you share ?.

If the issue is duplicate, forgive me.

error with attachment

hi there i have a problem with I tried to access to attachment file, this is my code

gmail.inbox.emails.each do |email|
  if !email.message.attachments.empty?
    email.attachments[0].save_to_file("~/")
  end
end

and this is the error that it throws

gems/mail-2.4.4/lib/mail/message.rb:1289:in `method_missing': undefined method `save_to_file' for #<Mail::Part:0x007ffca9a11d98> (NoMethodError)

Stringify_Keys Error for Ruby-Gmail 0.2.1

I wrote this in my ruby controller:

@imap = Gmail.new(current_user.google_email,
                              current_user.google_password) do |g|
  emails = g.inbox.emails(:after => 2.days.ago)
  emails.each do |email|
    logger.debug "................................................................................."
    logger.debug email
    logger.debug email.message
    logger.debug "................................................................................."

When I access "logger.debug email.message", i got this error:
.................................................................................

Gmail::Message:0xf5ba518

NoMethodError (undefined method `stringify_keys!' for #String:0xf5b35ec):

Please help me how to solve this error in ruby-gmail 0.2.1

Thanks,
Yacobus

shared-mime-info needs updated for ruby1.9

Contacted the author, hopefully it will be fixed soon.

To fix for ruby1.9, replace line 250 of shared-mime-info.rb with the following:

enum = @globs.each_key rescue Enumerable::Enumerator.new(@globs, :each_key)

invalid byte sequence in UTF-8

ubuntu interpid
last ruby

require 'gmail'

ArgumentError: invalid byte sequence in UTF-8
from /usr/local/lib/ruby/gems/1.9.1/gems/shared-mime-info-0.1/lib/shared-mime-info.rb:344:in block (2 levels) in load_magic' from /usr/local/lib/ruby/gems/1.9.1/gems/shared-mime-info-0.1/lib/shared-mime-info.rb:343:ineach'
from /usr/local/lib/ruby/gems/1.9.1/gems/shared-mime-info-0.1/lib/shared-mime-info.rb:343:in block in load_magic' from /usr/local/lib/ruby/gems/1.9.1/gems/shared-mime-info-0.1/lib/shared-mime-info.rb:335:inopen'
from /usr/local/lib/ruby/gems/1.9.1/gems/shared-mime-info-0.1/lib/shared-mime-info.rb:335:in load_magic' from /usr/local/lib/ruby/gems/1.9.1/gems/shared-mime-info-0.1/lib/shared-mime-info.rb:375:inblock in module:MIME'
from /usr/local/lib/ruby/gems/1.9.1/gems/shared-mime-info-0.1/lib/shared-mime-info.rb:370:in each' from /usr/local/lib/ruby/gems/1.9.1/gems/shared-mime-info-0.1/lib/shared-mime-info.rb:370:inmodule:MIME'
from /usr/local/lib/ruby/gems/1.9.1/gems/shared-mime-info-0.1/lib/shared-mime-info.rb:33:in <top (required)>' from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-gmail-0.0.8/lib/mime/message.rb:2:inrequire'
from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-gmail-0.0.8/lib/mime/message.rb:2:in <top (required)>' from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-gmail-0.0.8/lib/gmail/message.rb:1:inrequire'
from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-gmail-0.0.8/lib/gmail/message.rb:1:in <top (required)>' from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-gmail-0.0.8/lib/gmail.rb:118:inrequire'
from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-gmail-0.0.8/lib/gmail.rb:118:in <top (required)>' from (irb):1:inrequire'
from (irb):1
from /usr/local/bin/irb:12:in `

'>>

undefined method `peek=' for #<Gmail>

When I try to user 'peek' function I got an exception.
I can't find this method on rdoc documentation, but in github main page this function is present on tutorial.
Does that function still present in code by different name?

support for nested labels

Are nested labels provided in the interface?
I tried to use gmail.label("a").label("b"), but an exception is raised.

Error in MultipartEmail for ruby-gmail.0.0.8

Hi Bro:

I got this error message when trying to get html message with this error :

undefined method find_parts' for "This is a multi-part message in MIME format.\r\n":String D:/ruby/lib/ruby/gems/1.8/gems/ruby-gmail-0.0.8/lib/mime/entity.rb:124:infind_parts'
D:/ruby/lib/ruby/gems/1.8/gems/ruby-gmail-0.0.8/lib/mime/entity.rb:123:in each' D:/ruby/lib/ruby/gems/1.8/gems/ruby-gmail-0.0.8/lib/mime/entity.rb:123:infind_parts'
D:/ruby/lib/ruby/gems/1.8/gems/ruby-gmail-0.0.8/lib/mime/entity.rb:112:in find_part' D:/ruby/lib/ruby/gems/1.8/gems/ruby-gmail-0.0.8/lib/mime/message.rb:37:inhtml'
D:/ruby/anton/Nebula/app/controllers/mails_controller.rb:21:in index' D:/ruby/anton/Nebula/app/controllers/mails_controller.rb:17:ineach'
D:/ruby/anton/Nebula/app/controllers/mails_controller.rb:17:in index' D:/ruby/lib/ruby/gems/1.8/gems/ruby-gmail-0.0.8/lib/gmail.rb:24:ininitialize'
D:/ruby/anton/Nebula/app/controllers/mails_controller.rb:15:in `new'

Thank you for any help
Jack

Here is my code:

user_email = Mail.create({ :subject => email.message.subject,
:message => email.message.html, #<--- Error here for multipart message
:sender => email.message.from,
:receiver => email.message.to,
:received_date => email.message.headers['date']
})

Error Saving Attachments

When calling message.save_attachments_to, or attachment.save_to_file i get this error:

/home/jnagro/.gem/ruby/1.8/gems/ruby-gmail-0.0.8/lib/ietf/rfc2045.rb:20:in `parse_rfc2045_content_from': nested *?+ in regexp: /\r\n--VS++wcV0S1rZb1Fb"(?:--)?(?:\r\n|$)/ (RegexpError)

Net::SMTPAuthenticationError

I keep getting this error every time I try to send an email:

gmail.deliver(email)
Net::SMTPAuthenticationError: 530 5.7.0 Must issue a STARTTLS command first. g4sm20621052ybh.7

    from /usr/lib/ruby/gems/1.8/gems/tlsmail-0.0.1/lib/net/smtp.rb:679:in `auth_plain'
    from /usr/lib/ruby/gems/1.8/gems/tlsmail-0.0.1/lib/net/smtp.rb:673:in `__send__'
    from /usr/lib/ruby/gems/1.8/gems/tlsmail-0.0.1/lib/net/smtp.rb:673:in `authenticate'
    from /usr/lib/ruby/gems/1.8/gems/tlsmail-0.0.1/lib/net/smtp.rb:488:in `do_start'
    from /usr/lib/ruby/gems/1.8/gems/tlsmail-0.0.1/lib/net/smtp.rb:440:in `start'
    from /usr/lib/ruby/gems/1.8/gems/mail-2.2.1/lib/mail/network/delivery_methods/smtp.rb:101:in `deliver!'
    from /usr/lib/ruby/gems/1.8/gems/mail-2.2.1/lib/mail/message.rb:238:in `deliver!'
    from /usr/lib/ruby/gems/1.8/gems/ruby-gmail-0.2.1/lib/gmail.rb:85:in `deliver'

deadlock on gmail.inbox.emails

Hey guys.

Here's my code:

Gmail.new('email', 'password') do |gmail|
gmail.inbox.emails(:unread).each do |e|
...
end
end

I can't pass from gmail.inbox.emails, I always get the following errors:

deadlock 0xb5825108: sleep:- - /home/maino/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/monitor.rb:231
deadlock 0xb77b91b8: sleep:- (main) - /home/maino/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/monitor.rb:102
INTERNAL ERROR!!! Thread(0xb77b91b8): deadlock
/home/maino/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/monitor.rb:102:in stop' /home/maino/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/monitor.rb:102:inwait'
/home/maino/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/imap.rb:995:in get_tagged_response' /home/maino/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/imap.rb:1055:insend_command'
/home/maino/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/monitor.rb:242:in synchronize' /home/maino/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/imap.rb:1040:insend_command'
/home/maino/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/imap.rb:398:in select' /home/maino/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/monitor.rb:242:insynchronize'
/home/maino/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/imap.rb:396:in select' /home/maino/.rvm/gems/ruby-1.8.7-p352@rails2311/gems/ruby-gmail-0.3.0/lib/gmail.rb:119:inin_mailbox'
/home/maino/.rvm/gems/ruby-1.8.7-p352@rails2311/gems/ruby-gmail-0.3.0/lib/gmail/mailbox.rb:56:in emails' /home/maino/fontes/comexnfe/app/models/user.rb:49:ininitialize'
/home/maino/fontes/comexnfe/app/models/user.rb:49:in initialize' /home/maino/fontes/comexnfe/app/models/user.rb:47:innew'
/home/maino/fontes/comexnfe/app/models/user.rb:47:in checa_emails_para_importacao' /home/maino/fontes/comexnfe/app/models/user.rb:45:ineach'
/home/maino/fontes/comexnfe/app/models/user.rb:45:in checa_emails_para_importacao' (irb):5:inirb_binding'
/home/maino/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/irb/workspace.rb:52:in `irb_binding'

Any ideas?

error with attachment

hi there i have a problem with I tried to access to attachment file, this is my code

gmail.inbox.emails.each do |email|
  if !email.message.attachments.empty?
    email.attachments[0].save_to_file("~/")
  end
end

and this is the error that it throws

gems/mail-2.4.4/lib/mail/message.rb:1289:in `method_missing': undefined method `save_to_file' for #<Mail::Part:0x007ffca9a11d98> (NoMethodError)

IETF PARSING FAIL exception when trying to read most emails

I suspect this has to do with your problem in README: "May not correctly read malformed MIME messages. This could possibly be corrected by having IMAP parse the MIME structure"

If this is the case, how much work will be needed to parse the MIME structure with IMAP? It'd be good to be able to read all messages that GMail itself can read.

Thanks for the great work!

The Next Version

Shortly, I want to begin the next version of ruby-gmail.

This gem should live up to this description:

A Rubyesque interface to Gmail, with all the tools you'll need. Search, read and send multipart emails; archive, mark as read/unread, delete emails; and manage labels.

To get there I think these steps need to be taken:

  • convert to use the mail gem behind the scenes
  • sketch a newer gmail dsl
  • spec out high level stuff
  • figure out and full spec out labels

These are very generic todos, but I think they are the path forward. Labels are super important. Also being able to peak and not mark as read will be huge.

If anyone is interested in helping or has comments on the direction please feel free to comment here.

The work for 2.0 will take place on my fork.

count from 0 to 1 seems to not work

On an active connection, the number of unread emails can go from 1 to 0, but not from 0 to 1.

# example : the number of unread emails is at 0
gmail = Gmail.new(...)
puts "unread : #{gmail.inbox.count(:unread)}" # puts 0
# send a test email
puts "unread : #{gmail.inbox.count(:unread)}" # still puts 0
gmail = Gmail.new(...)
puts "unread : #{gmail.inbox.count(:unread)}" # puts 1
# read the email
puts "unread : #{gmail.inbox.count(:unread)}" # puts 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.