{ "info": { "author": "Al Sweigart", "author_email": "al@inventwithpython.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "EZGmail\n======\n\nA Pythonic interface to the Gmail API that actually works as of June 2019.\n\nThe Gmail API quickstart doesn't actually seem to work on Python 3 without some adjustments, and the entire documentation is a bit much for someone who just wants to read and send emails from their Gmail account. EZGmail just works.\n\nThe Gmail API documentation by Google is available at https://developers.google.com/gmail/api/\n\nInstallation\n------------\n\nTo install with pip, run:\n\n pip install ezgmail\n\nYou will need to download a *credentials-gmail.json* file by going to https://developers.google.com/gmail/api/quickstart/python and clicking the **Enable the Gmail API** button (after logging in to your Gmail account). You will need to rename the downloaded *credentials.json* file to *credentials-gmail.json*.\n\nOnce you have the *credentials-gmail.json* file, the first time you run ``import ezgmail`` it will bring up a window asking you to log in to your Gmail account and allow \"Quickstart\" to access it. A *token-gmail.json* file will be generated which your script can use to access your account.\n\nFuture calls to ``ezgmail.init()`` or any other ``ezgmail`` function won't require this token-generating step. The ``gmail.init()`` function is automatically called when any other ``ezgmail`` function is called.\n\n\nQuickstart Guide\n----------------\n\nAfter you've downloaded a *credentials-gmail.json* and *token-gmail.json* file, you can import EZGmail with ``import ezgmail``. To see what email address you are sending from, examine ``ezgmail.EMAIL_ADDRESS`` (this is configured by the *token-gmail.json* file you're using, and you must first call ``ezgmail.init()`` or some other ``ezgmail`` function first):\n\n >>> import ezgmail\n >>> ezgmail.EMAIL_ADDRESS\n 'example@gmail.com'\n\nTo send an email from your \"example@gmail.com\" account:\n\n >>> import ezgmail\n >>> ezgmail.send('recipient@example.com', 'Subject line', 'Body of the email', ['attachment1.jpg', 'attachment2.mp3'])\n\nThe ``attachments`` argument is optional, and if you only have one attachment you can just specify the filename string. Also note that Gmail will most likely filter any emails that contain *.exe*, *.zip*, or any other suspicious attachments.\n\nThe cc and bcc fields are also optional keyword arguments:\n\n >>> import ezgmail\n >>> ezgmail.send('recipient@example.com', 'Subject line', 'Body of the email', cc='friend@example.com', bcc='otherfriend@example.com,someoneelse@example.com')\n\nThe main classes in ``ezgmail`` are ``GmailThread`` and ``GmailMessage``. A ``GmailThread`` is a chain of emails replying to one another, while a ``GmailMessage`` is an individual email in a thread.\n\nTo retrieve unread emails:\n\n >>> import ezgmail\n >>> unreadThreads = ezgmail.unread() # Returns a list of GmailThread objects.\n\nThe ``summary()`` function is an easy way to print out info on a list of thread or message objects:\n\n >>> ezgmail.summary(unreadThreads)\n Jon, Al - Remember that old website Hamsterdance? LOL - Dec 09\n Al - This is a test email about gerbils. - Dec 09\n\nIf you want this info as a data structure, pass ``printInfo=False`` to ``summary()``:\n\n >>> ezgmail.summary(unreadThreads, printInfo=False)\n [(['Jon Smith ', 'Al Sweigart '], 'Remember that old website Hamsterdance? LOL', datetime.datetime(2018, 12, 9, 13, 29, 17)), (['Al Sweigart '], 'This is a test email about gerbils.', datetime.datetime(2018, 12, 9, 13, 25, 58))]\n\nThe ``GmailMessage`` objects of a thread are in the ``messages`` list attribute:\n\n >>> ezgmail.summary(unreadThreads[0].messages)\n Jon - Remember that old website Hamsterdance? LOL - Dec 09\n Al - Haha that's awesome! On Sun, Dec 9, 2018 at 1:28 PM Jon Smith <example@gmail.com> wrote: Remember that old website Hamsterdance? LOL - Dec 09\n\nThe ``GmailMessage`` objects have ``sender``, ``recipient``, ``subject``, ``body``, and ``timestamp`` attribues:\n\n >>> msg = unreadThreads[0].messages[0]\n >>> msg.sender\n 'Jon Smith '\n >>> msg.recipient\n 'Al Sweigart '\n >>> msg.subject\n 'Hamsterdance'\n >>> msg.body\n 'Remember that old website Hamsterdance? LOL\\r\\n'\n >>> msg.timestamp\n datetime.datetime(2018, 12, 9, 13, 28, 48)\n\nYou can also call the ``recent()`` method to get recent email threads:\n\n >>> import ezgmail\n >>> recentThreads = ezgmail.recent()\n >>> len(recentThreads)\n 22\n\nThe ``recent()`` and ``unread()`` functions are just convenient wrappers around ``search()``, which you can pass a query to (just like the query text field in the Gmail.com website):\n\n >>> import ezgmail\n >>> threads = ezgmail.search('mancala')\n >>> len(threads)\n 1\n >>> ezgmail.summary(threads[0])\n Al, Jon - Zanzibar > Mancala is one of the oldest known games to still be widely played today. > Mancala is a generic name for a - Dec 08\n\nThe ``search()`` function can accept search operators just like the query text field:\n\n* label:UNREAD\n* from:al@inventwithpython.com\n* subject:hello\n* has:attachment\n\nMore are described at https://support.google.com/mail/answer/7190?hl=en\n\nThe ``search()``, ``recent()``, and ``unread()`` can also accept a ``maxResults`` keyword argument that is set to 25 by default. This sets an upper limit on how many threads/messages will be returned. API usage quotas are posted at https://developers.google.com/gmail/api/v1/reference/quota (roughly one million requests a day (and 25 per second) for the free tier).\n\nAccessing an email or thread doesn't mark it as unread automatically. You must do that yourself by calling the ``markAsRead()`` method of the ``GmailThread`` or ``GmailMessage`` object. (There is also a corresponding ``markAsUnread()`` function.) You can also call ``ezgmail.markAsRead()`` and pass it a list of ``GmailThread`` or ``GmailMessage`` objects.\n\n >>> import ezgmail\n >>> unreadThreads = ezgmail.unread()\n >>> ezgmail.markAsRead(unreadThreads) # Marks all the GmailThread objects in the unreadThreads list as read.\n >>> # Or you can do:\n >>> for unreadThread in unreadThreads:\n ... unreadThread.markAsRead() # Mark the individual GmailThread objects as read.\n\nThese two functions make add/remove the ``'UNREAD'`` label using EZGmail's ``addLabel()`` and ``removeLabel()`` functions:\n\n >>> import ezgmail\n >>> unreadThreads = ezgmail.unread()\n >>> ezgmail.removeLabel(unreadThreads, 'UNREAD') # Also marks threads as read.\n >>> ezgmail.addLabel(unreadThreads, 'UNREAD') # Marks them as unread again.\n >>> # Or you can do:\n >>> for unreadThread in unreadThreads:\n ... unreadThread.removeLabel(unreadThreads, 'UNREAD') # Mark the individual GmailThread objects as read.\n\n(Currently EZGmail doesn't have functions for adding/deleting/managing custom labels.)\n\nTo view the attachments of an email, look at the ``GmailMessage`` object's ``attachments`` dictionary. The keys are the filenames of the attachments. You can either call the ``downloadAttachment()`` or ``downloadAllAttachments()`` methods:\n\n >>> import ezgmail\n >>> threads = ezgmail.search('See the attached files')\n >>> threads[0].messages[0].attachments\n\t>>> import pprint\n\t>>> pprint.pprint(threads[0].messages[0].attachments)\n\t{'a.png': {'id': 'ANGjdJ8eLDbjBpFTfvpuQ2HfR_iwp59XLUIl-IHW8eJcexMsxBYoPCZAXcX16rnqcbJZTknF5r3GmnM1W9n4vAE1oiVgUa4S4zBmNs7rd5PzFwLjO2vU3hp3_9SEZv-KBqVxi9nuNjarxhFqp3mxw6E5mqEYmFOYtT7Gx6CZbLaJuUox9GaWu-W9B4-XPDjwKkEfCdJ21FlOl-CsC6isZgD2Vh-ghh1haZN_2sifccznLv61ZW_KmqPKFcV1j7cXMQVqWU7bkgdH8do4Msc3QsG2ly_PNRid4-7gihsXaLI1ko_j3LSvsoLHFP3edhxh6YKQ2OdMhyZh5lqjmfT1TXgSo7hY16P_ScDO5MnWvmKscf_Hm5y5D4DHfwOq4--Otivoq2WVkVucVUJBkAoB',\n\t 'size': 833609},\n\t 'b.png': {'id': 'ANGjdJ_WYMmPmy2Dd2VBgvVoLAd1p3ARxGXKIzVfKqAiLhvKSBmEowYqFCdHbMJYlDZy4IWBGLg0eQCllMI0icqamM7vfMxBW2irJVogLM6SUT9cIcJFMSF7UhzU2I26bho086J7NjnX5u4kqYj_LHchowO56vTdKLRRsaJ2gfW0esz3cDFZzvthdR4wyBKEIeCJv7OJmFiaJIRf9f1KmFfKPLo9GZSyD2RMXdd6Qa2M3uN9pgT6sZ-OQx3e6aNDAKWh5GCeSiuIt_Z7GsDCdzVJjakMJx5FRFhp5zIck0p04AHnYhKfy1BipWmf7G-DAKzgJHAhFimBVUIBeFsHrqEGxDlevD7lK4ZBeb8cluSmYyEsRkSPSMYMlp-x1GVw25gqMnMVkGMKPfwj38iB',\n \t 'size': 335911}}\n\t>>> threads[0].messages[0].downloadAttachment('a.png') # Download to current working directory.\n >>> threads[0].messages[0].downloadAttachment('b.png', '/path/to/save/in')\n >>> threads[0].messages[0].downloadAllAttachments() # Easier way to save all attachments.\n\n\nLimitations\n-----------\n\nCurrently, EZGmail cannot do the following:\n\n* Read or set labels. (Including marking emails as read.)\n* Sending emails with cc and bcc fields.\n* A lot of other basic features. This package is just a start!\n\nContribute\n----------\n\nIf you'd like to contribute to EZGmail, check out https://github.com/asweigart/ezgmail or email al@inventwithpython.com", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/asweigart/ezgmail", "keywords": "", "license": "GPLv3+", "maintainer": "", "maintainer_email": "", "name": "EZGmail", "package_url": "https://pypi.org/project/EZGmail/", "platform": "", "project_url": "https://pypi.org/project/EZGmail/", "project_urls": { "Homepage": "https://github.com/asweigart/ezgmail" }, "release_url": "https://pypi.org/project/EZGmail/0.0.7/", "requires_dist": null, "requires_python": "", "summary": "A Pythonic interface to the Gmail API that actually works as of June 2019.", "version": "0.0.7" }, "last_serial": 5438651, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "cb4b12383b7d498ac582c859bb8715f6", "sha256": "9f6151b5a34faafa05decdead00c8fe3a8e92b8360a21af266362f9fb1f01ba6" }, "downloads": -1, "filename": "EZGmail-0.0.1.tar.gz", "has_sig": false, "md5_digest": "cb4b12383b7d498ac582c859bb8715f6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8195, "upload_time": "2018-12-11T00:20:04", "url": "https://files.pythonhosted.org/packages/9a/1c/29a69d280c3110215f9b8a0451bf8685d376f3e93bdaef15fd17ad13311e/EZGmail-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "0e729dc7ef5a2e123382d93c2a1d1bb9", "sha256": "cd91bda5d91dbe0aade9a31a1e51dc88c4751dda63bd93f75581e1f545dbe3ea" }, "downloads": -1, "filename": "EZGmail-0.0.2.tar.gz", "has_sig": false, "md5_digest": "0e729dc7ef5a2e123382d93c2a1d1bb9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8303, "upload_time": "2018-12-11T00:44:50", "url": "https://files.pythonhosted.org/packages/36/5b/10c5f48aa41437cf6f9e83fb9ffd5d58bb508116a55d1d3b28d53a559c75/EZGmail-0.0.2.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "0b31fb7714f27eeaea580a6162494754", "sha256": "18df667c47abc99a17da0da02e820e2a8850192983090539916731c459b79056" }, "downloads": -1, "filename": "EZGmail-0.0.4.tar.gz", "has_sig": false, "md5_digest": "0b31fb7714f27eeaea580a6162494754", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10312, "upload_time": "2018-12-14T07:04:21", "url": "https://files.pythonhosted.org/packages/d4/21/52c303c69cafc01c7813204018fea0fe08012dd0151348233120a5dd5193/EZGmail-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "737e740c8364b3cd40dfb758891a568a", "sha256": "f7d550984567c069e182545251ce12de7a2be142f9c57375b0675625852581d0" }, "downloads": -1, "filename": "EZGmail-0.0.5.tar.gz", "has_sig": false, "md5_digest": "737e740c8364b3cd40dfb758891a568a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11301, "upload_time": "2019-03-17T20:29:49", "url": "https://files.pythonhosted.org/packages/cb/ed/7cc123feb94f0b16836a043dc2b0113e0b9a1a74215e4b4253a4f4ac839f/EZGmail-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "7f533e5aca3e4b127ec681644573dd47", "sha256": "fc78947bf38386926e2aa42688fb25c07705fafda8a42f3ce3b0a2af75d30f18" }, "downloads": -1, "filename": "EZGmail-0.0.6.tar.gz", "has_sig": false, "md5_digest": "7f533e5aca3e4b127ec681644573dd47", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11350, "upload_time": "2019-06-13T18:52:29", "url": "https://files.pythonhosted.org/packages/3b/d6/d902f58f5b5d3295ef8a37b83476abe6c91f5db4b9c454aea4bf913e7b93/EZGmail-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "876291bf7173195720bec8a95e066cb3", "sha256": "949bb9143a5aac7ed431ee6e2d3cb4f507d48cc5d7f2178804a992ce400b0cf7" }, "downloads": -1, "filename": "EZGmail-0.0.7.tar.gz", "has_sig": false, "md5_digest": "876291bf7173195720bec8a95e066cb3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11535, "upload_time": "2019-06-24T01:52:48", "url": "https://files.pythonhosted.org/packages/ad/fe/11c18cc79f6e0e09edb3aeb111ae9f326e02ee87171ef1ff35884d04bb7d/EZGmail-0.0.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "876291bf7173195720bec8a95e066cb3", "sha256": "949bb9143a5aac7ed431ee6e2d3cb4f507d48cc5d7f2178804a992ce400b0cf7" }, "downloads": -1, "filename": "EZGmail-0.0.7.tar.gz", "has_sig": false, "md5_digest": "876291bf7173195720bec8a95e066cb3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11535, "upload_time": "2019-06-24T01:52:48", "url": "https://files.pythonhosted.org/packages/ad/fe/11c18cc79f6e0e09edb3aeb111ae9f326e02ee87171ef1ff35884d04bb7d/EZGmail-0.0.7.tar.gz" } ] }