{"id":13631819,"url":"https://github.com/dcparker/ruby-gmail","last_synced_at":"2025-04-17T22:32:04.234Z","repository":{"id":45810506,"uuid":"377945","full_name":"dcparker/ruby-gmail","owner":"dcparker","description":"A Rubyesque interface to Gmail. Connect to Gmail via IMAP and manipulate emails and labels. Send email with your Gmail account via SMTP. Includes full support for parsing and generating MIME messages.","archived":false,"fork":false,"pushed_at":"2019-06-27T22:07:08.000Z","size":103,"stargazers_count":791,"open_issues_count":26,"forks_count":123,"subscribers_count":41,"default_branch":"master","last_synced_at":"2024-11-05T20:04:02.335Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://dcparker.github.com/ruby-gmail","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dcparker.png","metadata":{"files":{"readme":"README.markdown","changelog":"History.txt","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-11-19T04:32:25.000Z","updated_at":"2024-10-30T04:32:50.000Z","dependencies_parsed_at":"2022-07-18T21:34:21.788Z","dependency_job_id":null,"html_url":"https://github.com/dcparker/ruby-gmail","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcparker%2Fruby-gmail","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcparker%2Fruby-gmail/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcparker%2Fruby-gmail/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcparker%2Fruby-gmail/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcparker","download_url":"https://codeload.github.com/dcparker/ruby-gmail/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223768654,"owners_count":17199357,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T22:02:39.698Z","updated_at":"2024-11-08T23:31:40.746Z","avatar_url":"https://github.com/dcparker.png","language":"Ruby","readme":"# Notice\n\nI have pushed verion 0.3.1 to rubygems.org (Yay, thanks Nick Quaranto for the help) which is a build straight from master.\n\nSecond, this gem is getting back on track. See [this issue here](https://github.com/dcparker/ruby-gmail/issues/58) for more information.\n\n# ruby-gmail\n\n* Code: [http://github.com/dcparker/ruby-gmail](http://github.com/dcparker/ruby-gmail)\n* Gem: [http://gemcutter.org/gems/ruby-gmail](http://rubygems.org/gems/ruby-gmail)\n\n## Author(s)\n\n* Daniel Parker of BehindLogic.com\n* Nathan Herald\n\nExtra thanks for specific feature contributions from:\n\n  * [Justin Perkins](http://github.com/justinperkins)\n  * [Mikkel Malmberg](http://github.com/mikker)\n  * [Julien Blanchard](http://github.com/julienXX)\n  * [Federico Galassi](http://github.com/fgalassi)\n\n## Description\n\nA 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.\n\n## Features\n\n* Search emails\n* Read emails (handles attachments)\n* Emails: Label, archive, delete, mark as read/unread/spam\n* Create and delete labels\n* Create and send multipart email messages in plaintext and/or html, with inline images and attachments\n* Utilizes Gmail's IMAP \u0026 SMTP, MIME-type detection and parses and generates MIME properly.\n\n## Problems:\n\n* May not correctly read malformed MIME messages. This could possibly be corrected by having IMAP parse the MIME structure.\n* Cannot grab the plain or html message without also grabbing attachments. It might be nice to lazy-[down]load attachments.\n\n## Example Code:\n\n### 1) Require gmail\n\n    require 'gmail'\n    \n### 2) Start an authenticated gmail session\n\n    #    If you pass a block, the session will be passed into the block,\n    #    and the session will be logged out after the block is executed.\n    gmail = Gmail.new(username, password)\n    # ...do things...\n    gmail.logout\n\n    Gmail.new(username, password) do |gmail|\n      # ...do things...\n    end\n\n### 3) Count and gather emails!\n    \n    # Get counts for messages in the inbox\n    gmail.inbox.count\n    gmail.inbox.count(:unread)\n    gmail.inbox.count(:read)\n\n    # Count with some criteria\n    gmail.inbox.count(:after =\u003e Date.parse(\"2010-02-20\"), :before =\u003e Date.parse(\"2010-03-20\"))\n    gmail.inbox.count(:on =\u003e Date.parse(\"2010-04-15\"))\n    gmail.inbox.count(:from =\u003e \"myfriend@gmail.com\")\n    gmail.inbox.count(:to =\u003e \"directlytome@gmail.com\")\n\n    # Combine flags and options\n    gmail.inbox.count(:unread, :from =\u003e \"myboss@gmail.com\")\n    \n    # Labels work the same way as inbox\n    gmail.mailbox('Urgent').count\n    \n    # Getting messages works the same way as counting: optional flag, and optional arguments\n    # Remember that every message in a conversation/thread will come as a separate message.\n    gmail.inbox.emails(:unread, :before =\u003e Date.parse(\"2010-04-20\"), :from =\u003e \"myboss@gmail.com\")\n\n    # Search the same way you do on Gmail's web interface:\n    gmail.inbox.emails(gm: 'before:2010-02-20 after:2010-03-20')\n    gmail.inbox.emails(gm: 'on:2010-04-15')\n    gmail.inbox.emails(gm: 'from:myfriend@gmail.com')\n    gmail.inbox.emails(gm: 'to:myfriend@gmail.com')\n    gmail.inbox.emails(gm: 'is:read from:myboss@gmail.com \"you are a great employee\"')\n\n    # Get messages without marking them as read on the server.\n    gmail.peek = true\n    gmail.inbox.emails(:unread, :before =\u003e Date.parse(\"2010-04-20\"), :from =\u003e \"myboss@gmail.com\")\n    \n### 4) Work with emails!\n\n    # any news older than 4-20, mark as read and archive it...\n    gmail.inbox.emails(:before =\u003e Date.parse(\"2010-04-20\"), :from =\u003e \"news@nbcnews.com\").each do |email|\n      email.mark(:read) # can also mark :unread or :spam\n      email.archive!\n    end\n\n    # delete emails from X...\n    gmail.inbox.emails(:from =\u003e \"x-fiancé@gmail.com\").each do |email|\n      email.delete!\n    end\n\n    # Save all attachments in the \"Faxes\" label to a folder\n    folder = \"/where/ever\"\n    gmail.mailbox(\"Faxes\").emails.each do |email|\n      email.attachments.each do |attachment|\n        file = File.new(folder + attachment.filename, \"w+\")\n        file \u003c\u003c attachment.decoded\n        file.close\n      end\n    end\n\n    # Add a label to a message\n    email.label(\"Faxes\")\n\n    # Or \"move\" the message to a label\n    email.move_to(\"Faxes\")\n\n### 5) Create new emails!\n\nCreating emails now uses the amazing [Mail](http://rubygems.org/gems/mail) rubygem. See its [documentation here](http://github.com/mikel/mail). 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.\n\n    gmail.deliver do\n      to \"email@example.com\"\n      subject \"Having fun in Puerto Rico!\"\n      text_part do\n        body \"Text of plaintext message.\"\n      end\n      html_part do\n        content_type 'text/html; charset=UTF-8'\n        body \"\u003cp\u003eText of \u003cem\u003ehtml\u003c/em\u003e message.\u003c/p\u003e\"\n      end\n      add_file \"/path/to/some_image.jpg\"\n    end\n    # Or, generate the message first and send it later\n    email = gmail.generate_message do\n      to \"email@example.com\"\n      subject \"Having fun in Puerto Rico!\"\n      body \"Spent the day on the road...\"\n    end\n    email.deliver!\n    # Or...\n    gmail.deliver(email)\n\n## Requirements\n\n* ruby\n* net/smtp\n* net/imap\n* tmail\n* shared-mime-info rubygem (for MIME-detection when attaching files)\n\n## Install\n\n    gem install ruby-gmail\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2009 BehindLogic\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":["Ruby","Third-party APIs"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcparker%2Fruby-gmail","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcparker%2Fruby-gmail","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcparker%2Fruby-gmail/lists"}