{"id":18267515,"url":"https://github.com/anonymerniklasistanonym/sendgmailsimplified","last_synced_at":"2025-10-29T23:31:03.379Z","repository":{"id":52313534,"uuid":"100541338","full_name":"AnonymerNiklasistanonym/SendGmailSimplified","owner":"AnonymerNiklasistanonym","description":"Send with only 3 lines of python code a email over the official Gmail API. Easy to add and simple to use. Attachments only supported on python 2.","archived":false,"fork":false,"pushed_at":"2021-04-30T20:39:33.000Z","size":32,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-22T16:10:02.853Z","etag":null,"topics":["cron","easy-to-use","gmail-api","python","python-api","send-email","simple"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AnonymerNiklasistanonym.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-16T23:32:39.000Z","updated_at":"2020-06-02T14:54:57.000Z","dependencies_parsed_at":"2022-08-22T15:00:44.274Z","dependency_job_id":null,"html_url":"https://github.com/AnonymerNiklasistanonym/SendGmailSimplified","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnonymerNiklasistanonym%2FSendGmailSimplified","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnonymerNiklasistanonym%2FSendGmailSimplified/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnonymerNiklasistanonym%2FSendGmailSimplified/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnonymerNiklasistanonym%2FSendGmailSimplified/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AnonymerNiklasistanonym","download_url":"https://codeload.github.com/AnonymerNiklasistanonym/SendGmailSimplified/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238909465,"owners_count":19550843,"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":["cron","easy-to-use","gmail-api","python","python-api","send-email","simple"],"created_at":"2024-11-05T11:27:43.928Z","updated_at":"2025-10-29T23:30:58.103Z","avatar_url":"https://github.com/AnonymerNiklasistanonym.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SendGmailSimplified\nSend with only 3 lines of python code an email over the official Gmail API. Easy to add and simple to use. Attachments only supported on python 2.\n\n**Virtual environment:** [How to setup and use `virtualenv` to run this script](VIRTUALENV.md)\n\n\n\n## What is this API?\n\nThis python API is nothing new or groundbreaking. I just wanted to send an email with the official Gmail API with nothing but 2 Lines in the code and one import in python.\n\nThis could make and made my python `Cron` job scripts, which check different things over the day really effective, because I can now very easy integrate the Gmail API and send notification or emails within one line anywhere in the script.\n\nI connected with some people and read the official Google Documentation and... now you and everyone can use an optimize it (MIT license).\n\nHave fun!\n\n\n\n**Attention:**\n\nIt seems like the current version is only fully supported on python 2.* (tested with 2.7.13 on my Raspberry Pi 3).\nIf you are on python 3.* only plain text or html text without attachments will work.\n\n\n\n## Instructions\n\n(Source: [Google Developers Gmail API Python](https://developers.google.com/gmail/api/quickstart/python))\n\n### 0. Create or Have a Google account\n\nObviously you first need a Google account and logged into Gmail for once to set up everything.\n\n### 1. Google Developer Console setup\n\nVisit the [Google API website](https://console.developers.google.com/start/api?id=gmail) and create a new Project:\n\n- Click `Select a project` at the top left (after you logged in with your Google account)\n  - Then named it and press continue on the next page\n- After some time the API is activated and a button `Go to credentials` will appear\n  - Simple: Click `Cancel` at the bottom of the page\n- Now you will find yourself in a tab interface\n  - Click the tab which is named `OAuth consent screen`\n    - Select the right email address\n    - Enter the name of your project/service/product\n    - You can do more but for now you are ready and can press `Save`\n  - Back in the tab interface click the tab which is named `Credentials`\n    - Now we want to create credentials and therefore expand the button `Create credentials` by clicking the triangle\n    - Now let's click the entry `OAuth client ID`\n      - Choose there your application type\n        (I chose `Other` and entered the name of my service + \"ClientID\")\n    - Now a small window will pop up which we will instantly dismiss\n      (by clicking `OK`)\n  - But because we want the client ID we'll download the JSON file of the created client ID:\n    - Just click the arrow down next to the client ID entry (:arrow_down:)\n\nNow you have the necessary file with which we can set up the Gmail API.\n\n### 2. Set up the Gmail API\n\nThe following steps will be really easy:\n\n- Rename the downloaded JSON file to `client_secret.json`\n\nCopy the file to a desired directory of yourself.\n\nCreate another JSON file (just copy the following code in a text file and rename it `client_data.json`):\n\n```json\n{\n\t\"email\": \"yourMailAdresse@gmail.com\",\n\t\"email-name\": \"Your Name\",\n\t\"application-name\": \"Previous created service name\",\n\t\"permission-scope\": \"https://www.googleapis.com/auth/gmail.send\"\n}\n```\n\nEdit the file as following:\n\n- replace the placeholders for everything but the `permission-scope` line with your data\n- copy the file to another desired directory of yourself\n  (if you want it simple put it in the same directory)\n\n### 3. Install the Google API python client\n\nTherefore just open the console and enter:\n\n```\n$ pip install --upgrade google-api-python-client\n```\n\nAnd confirm if you didn't sudo'd.\n\n### 4. Activate the API in your python script\n\nThis is even simpler.\n\nYou now just need three lines to activate and test the API:\n\n```python\nfrom SendGmailSimplified import SimplifiedGmailApi\n\nGmailServer = SimplifiedGmailApi(\"gmail_api_files/client_data.json\", \"gmail_api_files/client_secret.json\", \"gmail_api_files\")\nGmailServer.send_plain(\"enterHereYourEmailAddress@gmail.com\", \"Test-Subject\", \"1,2,3,4...\\nTest, test\")\n```\n\nThe three paths are:\n\n| Path to `client_data.json`           | Path to `client_secret.json`           | Directory of [future] API file |\n| ------------------------------------ | -------------------------------------- | ------------------------------ |\n| `\"gmail_api_files/client_data.json\"` | `\"gmail_api_files/client_secret.json\"` | `\"gmail_api_files\"`            |\n\nNow execute the script.\n\n- A browser window should open itself and ask you to login with your Google account\n- Then allow the API to `Send email on your behalf` over your account\n\nAfter you clicked `Allow` the necessary file is automatically saved into the directory on your computer of your third parameter.\n\nIf you didn't get an email look in the console.\nProbably you find something like `403 - Message could not be send`.\n\nBut this is not a problem: Just click like the official Gmail API says on the link just to get forwarded back to the API Developer Console.\nThen you do what the text says (at least for me) and click `Enable`.\nNow run the script again.\n\n\n\n## Demo\n\nIf you want a fast start into how to use the API just take a look into the [`demo.py`](demo.py) script:\n\n```python\nfrom SendGmailSimplified import SimplifiedGmailApi\n\n\n# Send for demo uses emails to you or someone else:\nyourEmailAddress = \"enterHereYourEmailAddress@gmail.com\"\n\n\n\"\"\"\nSetup line:\n\"\"\"\n\n# Replace the placeholders and enter your paths like the README.md says\nDemoServer = SimplifiedGmailApi(\"gmail_api_files/client_data.json\", \"gmail_api_files/client_secret.json\", \"gmail_api_files\")\n\n\n\"\"\"\nSend normal text/HTML emails:\n\"\"\"\n\n# Send a plain text message\nDemoServer.send_plain(yourEmailAddress, \"Test-Plain-Subject\", \"1,2,3,4...\\nTest, test\")\n\n# Send a HTML text message\nDemoServer.send_html(yourEmailAddress, \"Test-HTML-Subject\", \"\u003chtml\u003e\u003cbody\u003e1,2,3,4...\\nTest, test\u003c/body\u003e\u003c/html\u003e\")\n\n\n\"\"\"\nSend emails with attachments:\n(Currently only working on python 2.* not python 3.*)\n\"\"\"\n\n# Enter a path to a file (\u003c 25mb) that you want to attach\nattachment = \"demo.py\"\n\n# Send a plain text message with attachments\nDemoServer.send_plain_with_attachment(yourEmailAddress, \"Test-Plain-With-Attachment-Subject\", \"1,2,3,4...\\nTest, test\", attachment)\n\n\n# Enter paths to files (\u003c 25mb) that you want to attach\nattachments = [\"demo.py\", \"SendGmailSimplified.py\"]\n\n# Send a HTML text message with attachments\nDemoServer.send_html_with_attachments(yourEmailAddress, \"Test-HTML-With-Attachments-Subject\", \"\u003chtml\u003e\u003cbody\u003e1,2,3,4...\\nTest, test\u003c/body\u003e\u003c/html\u003e\", attachments)\n\n\n\"\"\"\nBonus: Send any or in this case a HTML text message to more than one person\n(by using a list and ', '.join(list))\n\"\"\"\n\n# Enter another email address\nanotherEmailAddress = \"anotherCool@email.com\"\n\n# Add all recipients to a list\nemail_list = [yourEmailAddress, anotherEmailAddress]\n\n# Add the list with ', '.join(list) instead of a single email address\nDemoServer.send_html(', '.join(email_list), \"Test-HTML-Multiple-Recipients-Subject\", \"\u003chtml\u003e\u003cbody\u003e1,2,3,4...\\nTest, test\u003c/body\u003e\u003c/html\u003e\")\n```\n\nJust input your email and change all attachment paths to real files + replace the paths in line 8 and you are good to go. (Run it and you will see it).\n\n\n\n## How can you use it in your project as git submodule?\n\nIf you generally wanna know how to do it visit this site: https://github.com/blog/2104-working-with-submodules\n\n1. Open the console in the directory where you want to place the folder with all files from this repository\n\n2. Then enter:\n\n   ```\n   $ git submodule add https://github.com/AnonymerNiklasistanonym/SendGmailSimplified SimplifiedGmailApiSubmodule\n   ```\n\n3. If you want to use it in a script which is located in the same directory just add:\n\n   ```python\n   from SimplifiedGmailApiSubmodule.SendGmailSimplified import SimplifiedGmailApi\n   ```\n\n4. Now you can use the script like in the Demo\n\n5. If any updates be released and you want to update the submodule use:\n\n   ```\n   $ git submodule update --init --recursive\n   ```\n\n\n\n## Problems, ideas?\n\n- If this didn't worked for you message me, make an Issue and we try to help if we have time.\n- If you have any ideas, optimizations please message me too (or open a issue/pull-request).\n\n\n\n\n\n## Last words\n\nWe hope this API simplifies sending an email to someone with the official Gmail API without any headaches and many lines of code.\n\nThanks for using this simple API and have fun programming!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanonymerniklasistanonym%2Fsendgmailsimplified","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanonymerniklasistanonym%2Fsendgmailsimplified","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanonymerniklasistanonym%2Fsendgmailsimplified/lists"}