{"id":13595399,"url":"https://github.com/railsware/mailtrap-python","last_synced_at":"2025-04-14T11:23:05.710Z","repository":{"id":66242354,"uuid":"601236662","full_name":"railsware/mailtrap-python","owner":"railsware","description":"Official mailtrap.io Python client","archived":false,"fork":false,"pushed_at":"2024-08-07T17:11:29.000Z","size":32,"stargazers_count":38,"open_issues_count":1,"forks_count":3,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-03-28T00:41:33.336Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://mailtrap.io","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/railsware.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2023-02-13T16:43:00.000Z","updated_at":"2025-03-02T22:42:54.000Z","dependencies_parsed_at":"2024-02-01T06:49:44.780Z","dependency_job_id":"fe9c6b60-f6af-4787-9763-bdd7e07d453a","html_url":"https://github.com/railsware/mailtrap-python","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsware%2Fmailtrap-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsware%2Fmailtrap-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsware%2Fmailtrap-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsware%2Fmailtrap-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/railsware","download_url":"https://codeload.github.com/railsware/mailtrap-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248869299,"owners_count":21174849,"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-01T16:01:49.384Z","updated_at":"2025-04-14T11:23:05.687Z","avatar_url":"https://github.com/railsware.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"[![test](https://github.com/railsware/mailtrap-python/actions/workflows/main.yml/badge.svg)](https://github.com/railsware/mailtrap-python/actions/workflows/main.yml)\n[![PyPI](https://shields.io/pypi/v/mailtrap)](https://pypi.org/project/mailtrap/)\n[![downloads](https://shields.io/pypi/dm/mailtrap)](https://pypi.org/project/mailtrap/)\n\n\n# Official Mailtrap Python client\n\nThis Python package offers integration with the [official API](https://api-docs.mailtrap.io/) for [Mailtrap](https://mailtrap.io).\n\nQuickly add email sending functionality to your Python application with Mailtrap.\n\n## Compatibility with previous releases\n\nVersions of this package up to 1.0.1 were a different, unrelated project, that is now maintained as [Sendria](https://github.com/msztolcman/sendria). To continue using it, see [instructions](#information-for-version-1-users).\n\n## Installation\n\n### Prerequisites\n\n- Python version 3.6+\n\n### Install package\n\n```text\npip install mailtrap\n```\n\n## Usage\n\n### Minimal\n\n```python\nimport mailtrap as mt\n\n# create mail object\nmail = mt.Mail(\n    sender=mt.Address(email=\"mailtrap@example.com\", name=\"Mailtrap Test\"),\n    to=[mt.Address(email=\"your@email.com\")],\n    subject=\"You are awesome!\",\n    text=\"Congrats for sending test email with Mailtrap!\",\n)\n\n# create client and send\nclient = mt.MailtrapClient(token=\"your-api-key\")\nclient.send(mail)\n```\n\n### Full\n\n```python\nimport base64\nfrom pathlib import Path\n\nimport mailtrap as mt\n\nwelcome_image = Path(__file__).parent.joinpath(\"welcome.png\").read_bytes()\n\nmail = mt.Mail(\n    sender=mt.Address(email=\"mailtrap@example.com\", name=\"Mailtrap Test\"),\n    to=[mt.Address(email=\"your@email.com\", name=\"Your name\")],\n    cc=[mt.Address(email=\"cc@email.com\", name=\"Copy to\")],\n    bcc=[mt.Address(email=\"bcc@email.com\", name=\"Hidden Recipient\")],\n    subject=\"You are awesome!\",\n    text=\"Congrats for sending test email with Mailtrap!\",\n    html=\"\"\"\n    \u003c!doctype html\u003e\n    \u003chtml\u003e\n      \u003chead\u003e\n        \u003cmeta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"\u003e\n      \u003c/head\u003e\n      \u003cbody style=\"font-family: sans-serif;\"\u003e\n        \u003cdiv style=\"display: block; margin: auto; max-width: 600px;\" class=\"main\"\u003e\n          \u003ch1 style=\"font-size: 18px; font-weight: bold; margin-top: 20px\"\u003e\n            Congrats for sending test email with Mailtrap!\n          \u003c/h1\u003e\n          \u003cp\u003eInspect it using the tabs you see above and learn how this email can be improved.\u003c/p\u003e\n          \u003cimg alt=\"Inspect with Tabs\" src=\"cid:welcome.png\" style=\"width: 100%;\"\u003e\n          \u003cp\u003eNow send your email using our fake SMTP server and integration of your choice!\u003c/p\u003e\n          \u003cp\u003eGood luck! Hope it works.\u003c/p\u003e\n        \u003c/div\u003e\n        \u003c!-- Example of invalid for email html/css, will be detected by Mailtrap: --\u003e\n        \u003cstyle\u003e\n          .main { background-color: white; }\n          a:hover { border-left-width: 1em; min-height: 2em; }\n        \u003c/style\u003e\n      \u003c/body\u003e\n    \u003c/html\u003e\n    \"\"\",\n    category=\"Test\",\n    attachments=[\n        mt.Attachment(\n            content=base64.b64encode(welcome_image),\n            filename=\"welcome.png\",\n            disposition=mt.Disposition.INLINE,\n            mimetype=\"image/png\",\n            content_id=\"welcome.png\",\n        )\n    ],\n    headers={\"X-MT-Header\": \"Custom header\"},\n    custom_variables={\"year\": 2023},\n)\n\nclient = mt.MailtrapClient(token=\"your-api-key\")\nclient.send(mail)\n```\n\n### Using email template\n\n```python\nimport mailtrap as mt\n\n# create mail object\nmail = mt.MailFromTemplate(\n    sender=mt.Address(email=\"mailtrap@example.com\", name=\"Mailtrap Test\"),\n    to=[mt.Address(email=\"your@email.com\")],\n    template_uuid=\"2f45b0aa-bbed-432f-95e4-e145e1965ba2\",\n    template_variables={\"user_name\": \"John Doe\"},\n)\n\n# create client and send\nclient = mt.MailtrapClient(token=\"your-api-key\")\nclient.send(mail)\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on [GitHub](https://github.com/railsware/mailtrap-python). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).\n\n### Development Environment\n\n#### Clone the repo\n\n```bash\nhttps://github.com/railsware/mailtrap-python.git\ncd mailtrap-python\n```\n\n#### Install [tox](https://tox.wiki/en/latest/installation.html)\n\n`tox` is an environment orchestrator. We use it to setup local environments, run tests and execute linters.\n\n```bash\npython -m pip install --user tox\npython -m tox --help\n```\n\nTo setup virtual environments, run tests and linters use:\n\n```bash\ntox\n```\n\nIt will create virtual environments with all installed dependencies for each available python interpreter (starting from `python3.6`) on your machine.\nBy default, they will be available in `{project}/.tox/` directory. So, for instance, to activate `python3.11` environment, run the following:\n\n```bash\nsource .tox/py311/bin/activate\n```\n\n## Information for version 1 users\n\nIf you are a version 1 user, it is advised that you upgrade to [Sendria](https://github.com/msztolcman/sendria), which is the same package, but under a new name, and with [new features](https://github.com/msztolcman/sendria#changelog). However, you can also continue using the last v1 release by locking the version in pip:\n\n```sh\n# To use the FORMER version of the mailtrap package, now known as Sendria:\npip install --force-reinstall -v \"mailtrap==1.0.1\"\n```\n\n## License\n\nThe project is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Mailtrap project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frailsware%2Fmailtrap-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frailsware%2Fmailtrap-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frailsware%2Fmailtrap-python/lists"}