{"id":15018775,"url":"https://github.com/mailosaur/mailosaur-python","last_synced_at":"2026-03-16T09:33:48.433Z","repository":{"id":28984401,"uuid":"32510964","full_name":"mailosaur/mailosaur-python","owner":"mailosaur","description":"Mailosaur email and SMS testing library for Python","archived":false,"fork":false,"pushed_at":"2025-01-02T09:44:04.000Z","size":474,"stargazers_count":9,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-30T21:11:57.447Z","etag":null,"topics":["email","email-testing","end-to-end-testing","python","qa","qaautomation","robot-framework","selenium","sms","testing-tools","webdriver"],"latest_commit_sha":null,"homepage":"https://mailosaur.com/docs/languages/python/","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/mailosaur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-03-19T09:01:41.000Z","updated_at":"2025-01-02T09:40:34.000Z","dependencies_parsed_at":"2024-06-12T09:42:11.647Z","dependency_job_id":null,"html_url":"https://github.com/mailosaur/mailosaur-python","commit_stats":{"total_commits":120,"total_committers":8,"mean_commits":15.0,"dds":0.2833333333333333,"last_synced_commit":"bc01d56baa8fe39a7db1e04ce4346b6e6d36963a"},"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailosaur%2Fmailosaur-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailosaur%2Fmailosaur-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailosaur%2Fmailosaur-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailosaur%2Fmailosaur-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mailosaur","download_url":"https://codeload.github.com/mailosaur/mailosaur-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237890775,"owners_count":19382562,"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":["email","email-testing","end-to-end-testing","python","qa","qaautomation","robot-framework","selenium","sms","testing-tools","webdriver"],"created_at":"2024-09-24T19:52:26.626Z","updated_at":"2026-03-16T09:33:48.426Z","avatar_url":"https://github.com/mailosaur.png","language":"Python","readme":"# [Mailosaur - Python library](https://mailosaur.com/) \u0026middot; [![](https://github.com/mailosaur/mailosaur-python/workflows/CI/badge.svg)](https://github.com/mailosaur/mailosaur-python/actions) \n\nMailosaur lets you automate email and SMS tests as part of software development and QA.\n\n- **Unlimited test email addresses for all**  - every account gives users an unlimited number of test email addresses to test with.\n- **End-to-end (e2e) email and SMS testing** Allowing you to set up end-to-end tests for password reset emails, account verification processes and MFA/one-time passcodes sent via text message.\n- **Fake SMTP servers** Mailosaur also provides dummy SMTP servers to test with; allowing you to catch email in staging environments - preventing email being sent to customers by mistake.\n\n## Get Started\n\nThis guide provides several key sections:\n\n- [Mailosaur - Python library · ](#mailosaur---python-library--)\n  - [Get Started](#get-started)\n  - [Installation](#installation)\n    - [Set your API key](#set-your-api-key)\n    - [Create your code](#create-your-code)\n    - [API Reference](#api-reference)\n  - [Creating an account](#creating-an-account)\n  - [Test email addresses with Mailosaur](#test-email-addresses-with-mailosaur)\n  - [Find an email](#find-an-email)\n    - [What is this code doing?](#what-is-this-code-doing)\n  - [Find an SMS message](#find-an-sms-message)\n  - [Testing plain text content](#testing-plain-text-content)\n    - [Extracting verification codes from plain text](#extracting-verification-codes-from-plain-text)\n  - [Testing HTML content](#testing-html-content)\n    - [Working with HTML using Beautiful Soup](#working-with-html-using-beautiful-soup)\n  - [Working with hyperlinks](#working-with-hyperlinks)\n    - [Links in plain text (including SMS messages)](#links-in-plain-text-including-sms-messages)\n  - [Working with attachments](#working-with-attachments)\n  - [Working with images and web beacons](#working-with-images-and-web-beacons)\n    - [Remotely-hosted images](#remotely-hosted-images)\n    - [Triggering web beacons](#triggering-web-beacons)\n  - [Spam checking](#spam-checking)\n  - [Development](#development)\n  - [Contacting us](#contacting-us)\n\nYou can find the full [Mailosaur documentation](https://mailosaur.com/docs/) on the website.\n\nIf you get stuck, just contact us at support@mailosaur.com.\n\n## Installation\n\n```\npip install --upgrade mailosaur\n```\n\n### Set your API key\n\nGet your API key from the Mailosaur Dashboard and set it as an environment variable:\n\n```sh\nexport MAILOSAUR_API_KEY='your-api-key-here'\n```\n\n### Create your code\n\nThen import the library and create a client:\n\n```py\nfrom mailosaur import MailosaurClient\nmailosaur = MailosaurClient()\n```\n\n### API Reference\n\nThis library is powered by the Mailosaur [email \u0026 SMS testing API](https://mailosaur.com/docs/api/). You can easily check out the API itself by looking at our [API reference documentation](https://mailosaur.com/docs/api/) or via our Postman or Insomnia collections:\n\n[![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/6961255-6cc72dff-f576-451a-9023-b82dec84f95d?action=collection%2Ffork\u0026collection-url=entityId%3D6961255-6cc72dff-f576-451a-9023-b82dec84f95d%26entityType%3Dcollection%26workspaceId%3D386a4af1-4293-4197-8f40-0eb49f831325)\n [![Run in Insomnia}](https://insomnia.rest/images/run.svg)](https://insomnia.rest/run/?label=Mailosaur\u0026uri=https%3A%2F%2Fmailosaur.com%2Finsomnia.json)\n\n## Creating an account\n\nCreate a [free trial account](https://mailosaur.com/app/signup) for Mailosaur via the website.\n\nOnce you have this, navigate to the [API tab](https://mailosaur.com/app/project/api) to find the following values:\n\n- **Server ID** - Servers act like projects, which group your tests together. You need this ID whenever you interact with a server via the API.\n- **Server Domain** - Every server has its own domain name. You'll need this to send email to your server.\n- **API Key** - You can create an API key per server (recommended), or an account-level API key to use across your whole account. [Learn more about API keys](https://mailosaur.com/docs/managing-your-account/api-keys/).\n\n## Test email addresses with Mailosaur\n\nMailosaur gives you an **unlimited number of test email addresses** - with no setup or coding required!\n\nHere's how it works:\n\n* When you create an account, you are given a server.\n* Every server has its own **Server Domain** name (e.g. `abc123.mailosaur.net`)\n* Any email address that ends with `@{YOUR_SERVER_DOMAIN}` will work with Mailosaur without any special setup. For example:\n  * `build-423@abc123.mailosaur.net`\n  * `john.smith@abc123.mailosaur.net`\n  * `rAnDoM63423@abc123.mailosaur.net`\n* You can create more servers when you need them. Each one will have its own domain name.\n\n***Can't use test email addresses?** You can also [use SMTP to test email](https://mailosaur.com/docs/email-testing/sending-to-mailosaur/#sending-via-smtp). By connecting your product or website to Mailosaur via SMTP, Mailosaur will catch all email your application sends, regardless of the email address.*\n\n## Find an email\n\nIn automated tests you will want to wait for a new email to arrive. This library makes that easy with the `messages.get` method. Here's how you use it:\n\n```py\nfrom mailosaur import MailosaurClient\nfrom mailosaur.models import SearchCriteria\n\nmailosaur = MailosaurClient()\n\n# See https://mailosaur.com/app/project/api\nserver_id = \"abc123\"\nserver_domain = \"abc123.mailosaur.net\"\n\ncriteria = SearchCriteria()\ncriteria.sent_to = \"anything@\" + server_domain\n\nemail = mailosaur.messages.get(server_id, criteria)\n\nprint(email.subject) # \"Hello world!\"\n```\n\n### What is this code doing?\n\n1. Sets up an instance of `MailosaurClient` using the `MAILOSAUR_API_KEY` environment variable.\n2. Waits for an email to arrive at the server with ID `abc123`.\n3. Outputs the subject line of the email.\n\n## Find an SMS message\n\n**Important:** Trial accounts do not automatically have SMS access. Please contact our support team to enable a trial of SMS functionality.\n\nIf your account has [SMS testing](https://mailosaur.com/sms-testing/) enabled, you can reserve phone numbers to test with, then use the Mailosaur API in a very similar way to when testing email:\n\n```py\nfrom mailosaur import MailosaurClient\nfrom mailosaur.models import SearchCriteria\n\nmailosaur = MailosaurClient()\n\n# See https://mailosaur.com/app/project/api\nserver_id = \"abc123\"\nserver_domain = \"abc123.mailosaur.net\"\n\ncriteria = SearchCriteria()\ncriteria.sent_to = \"4471235554444\"\n\nsms = mailosaur.messages.get(server_id, criteria)\n\nprint(sms.text.body)\n```\n\n## Testing plain text content\n\nMost emails, and all SMS messages, should have a plain text body. Mailosaur exposes this content via the `text.body` property on an email or SMS message:\n\n```py\nprint(message.text.body) # \"Hi Jason, ...\"\n\nif \"Jason\" in message.text.body:\n  print('Email contains \"Jason\"')\n```\n\n### Extracting verification codes from plain text\n\nYou may have an email or SMS message that contains an account verification code, or some other one-time passcode. You can extract content like this using a simple regex.\n\nHere is how to extract a 6-digit numeric code:\n\n```py\nprint(message.text.body) # \"Your access code is 243546.\"\n\nmatch = re.search(\"([0-9]{6})\", message.text.body)\nprint(match.group()) # \"243546\"\n```\n\n[Read more](https://mailosaur.com/docs/test-cases/text-content/)\n\n## Testing HTML content\n\nMost emails also have an HTML body, as well as the plain text content. You can access HTML content in a very similar way to plain text:\n\n```py\nprint(message.html.body) # \"\u003chtml\u003e\u003chead ...\"\n```\n\n### Working with HTML using Beautiful Soup\n\nIf you need to traverse the HTML content of an email. For example, finding an element via a CSS selector, you can use the [Beautiful Soup](https://pypi.org/project/beautifulsoup4/) library.\n\n```sh\npip install beautifulsoup4\n```\n\n```py\nfrom bs4 import BeautifulSoup\n\n# ...\n\ndom = BeautifulSoup(message.html.body, 'html.parser')\n\nel = dom.find('.verification-code')\nverification_code = el.text\n\nprint(verification_code) # \"542163\"\n```\n\n[Read more](https://mailosaur.com/docs/test-cases/html-content/)\n\n## Working with hyperlinks\n\nWhen an email is sent with an HTML body, Mailosaur automatically extracts any hyperlinks found within anchor (`\u003ca\u003e`) and area (`\u003carea\u003e`) elements and makes these viable via the `html.links` array.\n\nEach link has a text property, representing the display text of the hyperlink within the body, and an href property containing the target URL:\n\n```py\n# How many links?\nprint(len(message.html.links)) # 2\n\nfirst_link = message.html.links[0]\nprint(first_link.text) # \"Google Search\"\nprint(first_link.href) # \"https://www.google.com/\"\n```\n\n**Important:** To ensure you always have valid emails. Mailosaur only extracts links that have been correctly marked up with `\u003ca\u003e` or `\u003carea\u003e` tags.\n\n### Links in plain text (including SMS messages)\n\nMailosaur auto-detects links in plain text content too, which is especially useful for SMS testing:\n\n```py\n# How many links?\nprint(len(message.text.links)) # 2\n\nfirst_link = message.text.links[0]\nprint(first_link.href) # \"https://www.google.com/\"\n```\n\n## Working with attachments\n\nIf your email includes attachments, you can access these via the `attachments` property:\n\n```py\n# How many attachments?\nprint(len(message.attachments)) # 2\n```\n\nEach attachment contains metadata on the file name and content type:\n\n```py\nfirst_attachment = message.attachments[0]\nprint(first_attachment.file_name) # \"contract.pdf\"\nprint(first_attachment.content_type) # \"application/pdf\"\n```\n\nThe `length` property returns the size of the attached file (in bytes):\n\n```py\nfirst_attachment = message.attachments[0]\nprint(first_attachment.length) # 4028\n```\n\n## Working with images and web beacons\n\nThe `html.images` property of a message contains an array of images found within the HTML content of an email. The length of this array corresponds to the number of images found within an email:\n\n```py\n# How many images in the email?\nprint(len(message.html.images)) # 1\n```\n\n### Remotely-hosted images\n\nEmails will often contain many images that are hosted elsewhere, such as on your website or product. It is recommended to check that these images are accessible by your recipients.\n\nAll images should have an alternative text description, which can be checked using the `alt` attribute.\n\n```py\nimage = message.html.images[0]\nprint(image.alt) # \"Hot air balloon\"\n```\n\n### Triggering web beacons\n\nA web beacon is a small image that can be used to track whether an email has been opened by a recipient.\n\nBecause a web beacon is simply another form of remotely-hosted image, you can use the `src` attribute to perform an HTTP request to that address:\n\n```py\nimport requests\n\n# ...\n\nconst image = message.html.images[0]\nprint(image.src) # \"https://example.com/s.png?abc123\"\n\n# Make an HTTP call to trigger the web beacon\nresponse = requests.get(image.src)\nprint(response.status_code) # 200\n```\n\n## Spam checking\n\nYou can perform a [SpamAssassin](https://spamassassin.apache.org/) check against an email. The structure returned matches the [spam test object](https://mailosaur.com/docs/api/#spam):\n\n```py\nresult = mailosaur.analysis.spam(message.id)\n\nprint(result.score) # 0.5\n\nfor r in result.spam_filter_results.spam_assassin:\n  print(r.rule)\n  print(r.description)\n  print(r.score)\n```\n\n## Development\n\nYou must have the following prerequisites installed:\n\n* [pip](https://pip.pypa.io/en/stable/installing/)\n\nInstall all development dependencies:\n\n```sh\npip install -r requirements.txt\n```\n\nThe test suite requires the following environment variables to be set:\n\n```sh\nexport MAILOSAUR_BASE_URL=https://mailosaur.com/\nexport MAILOSAUR_API_KEY=your_api_key\nexport MAILOSAUR_SERVER=server_id\n```\n\nRun all tests:\n\n```sh\npytest\n```\n\n## Contacting us\n\nYou can get us at [support@mailosaur.com](mailto:support@mailosaur.com)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmailosaur%2Fmailosaur-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmailosaur%2Fmailosaur-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmailosaur%2Fmailosaur-python/lists"}