# Fastapi-mail
The fastapi-mail is a simple lightweight mail system, for sending emails and attachments(individual && bulk)
[](https://raw.githubusercontent.com/sabuhish/fastapi-mail/master/LICENSE)
[](https://github.com/sabuhish/fastapi-mail/stargazers)
[](https://github.com/sabuhish/fastapi-mail/network)
[](https://github.com/sabuhish/fastapi-mail/issues)
[](https://pepy.tech/project/fastapi-mail)
### 🔨 Installation ###
```bash
python3 -m venv .venv
source .venv/bin/activate
pip install fastapi-mail
for aioredis and httpx
pip install 'fastapi-mail[aioredis]'
pip install 'fastapi-mail[httpx]'
```
Alternatively, if you prefer to use `poetry` for package dependencies:
```bash
poetry shell
poetry add fastapi-mail
for aioredis and httpx
poetry add 'fastapi-mail[aioredis]'
poetry add 'fastapi-mail[httpx]'
```
---
**Documentation**: [FastApi-MAIL](https://sabuhish.github.io/fastapi-mail/)
---
The key features are:
- sending emails either with FastApi or using asyncio module
- sending emails using FastApi background task managment
- sending files either from form-data or files from server
- Using Jinja2 HTML Templates
- **NameEmail support** - recipients can be specified as `"Name <email@domain.com>"` format
- email utils (utility allows you to check temporary email addresses, you can block any email or domain)
- email utils has two available classes ```DefaultChecker``` and ```WhoIsXmlApi```
- Unittests using FastapiMail
More information on [Getting-Started](https://sabuhish.github.io/fastapi-mail/getting-started/)
### Guide
```python
from typing import List
from fastapi import BackgroundTasks, FastAPI
from fastapi_mail import ConnectionConfig, FastMail, MessageSchema, MessageType, NameEmail
from pydantic import BaseModel, EmailStr
from starlette.responses import JSONResponse
class EmailSchema(BaseModel):
email: List[NameEmail] # Supports both "user@example.com" and "Name <user@example.com>" formats
conf = ConnectionConfig(
MAIL_USERNAME ="username",
MAIL_PASSWORD = "**********",
MAIL_FROM = "test@email.com",
MAIL_PORT = 465,
MAIL_SERVER = "mail server",
MAIL_STARTTLS = False,
MAIL_SSL_TLS = True,
USE_CREDENTIALS = True,
VALIDATE_CERTS = True
)
app = FastAPI()
html = """
<p>Thanks for using Fastapi-mail</p>
"""
@app.post("/email")
async def simple_send(email: EmailSchema) -> JSONResponse:
message = MessageSchema(
subject="Fastapi-Mail module",
recipients=email.dict().get("email"), # Can include "Name <email@domain.com>" format
body=html,
subtype=MessageType.html)
fm = FastMail(conf)
await fm.send_message(message)
return JSONResponse(status_code=200, content={"message": "email has been sent"})
```
## List of Examples
For more examples of using fastapi-mail please check:
[example](https://sabuhish.github.io/fastapi-mail/example/) section.
## Contributors ✨
Thanks goes to these wonderful
[People](https://github.com/sabuhish/fastapi-mail/blob/master/contributors.txt)
# Contributing
Contributions of any kind are welcome!
Before you start, please read [CONTRIBUTING](https://github.com/sabuhish/fastapi-mail/blob/master/CONTRIBUTING.md)
## LICENSE
[MIT](LICENSE)
Raw data
{
"_id": null,
"home_page": "https://github.com/sabuhish/fastapi-mail",
"name": "fastapi-mail",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0.0,>=3.10.0",
"maintainer_email": null,
"keywords": null,
"author": "Sabuhi Shukurov",
"author_email": "sabuhi.shukurov@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/5e/07/d067c5cd91313d17de7c582e7eb3851c83a0291491871b3c338cb48d19f6/fastapi_mail-1.5.7.tar.gz",
"platform": null,
"description": "\n# Fastapi-mail\n\nThe fastapi-mail is a simple lightweight mail system, for sending emails and attachments(individual && bulk)\n\n\n[](https://raw.githubusercontent.com/sabuhish/fastapi-mail/master/LICENSE)\n[](https://github.com/sabuhish/fastapi-mail/stargazers)\n[](https://github.com/sabuhish/fastapi-mail/network)\n[](https://github.com/sabuhish/fastapi-mail/issues)\n[](https://pepy.tech/project/fastapi-mail)\n\n\n### \ud83d\udd28 Installation ###\n\n\n```bash\npython3 -m venv .venv\n\nsource .venv/bin/activate\n\npip install fastapi-mail\n\nfor aioredis and httpx\n\npip install 'fastapi-mail[aioredis]'\npip install 'fastapi-mail[httpx]'\n\n```\n\nAlternatively, if you prefer to use `poetry` for package dependencies:\n\n```bash\npoetry shell\n\npoetry add fastapi-mail\n\nfor aioredis and httpx\n\npoetry add 'fastapi-mail[aioredis]'\npoetry add 'fastapi-mail[httpx]'\n```\n\n---\n**Documentation**: [FastApi-MAIL](https://sabuhish.github.io/fastapi-mail/)\n---\n\n\nThe key features are:\n\n- sending emails either with FastApi or using asyncio module \n- sending emails using FastApi background task managment\n- sending files either from form-data or files from server\n- Using Jinja2 HTML Templates\n- **NameEmail support** - recipients can be specified as `\"Name <email@domain.com>\"` format\n- email utils (utility allows you to check temporary email addresses, you can block any email or domain)\n- email utils has two available classes ```DefaultChecker``` and ```WhoIsXmlApi```\n- Unittests using FastapiMail\n\nMore information on [Getting-Started](https://sabuhish.github.io/fastapi-mail/getting-started/)\n\n\n### Guide\n\n\n```python\n\nfrom typing import List\n\nfrom fastapi import BackgroundTasks, FastAPI\nfrom fastapi_mail import ConnectionConfig, FastMail, MessageSchema, MessageType, NameEmail\nfrom pydantic import BaseModel, EmailStr\nfrom starlette.responses import JSONResponse\n\n\n\nclass EmailSchema(BaseModel):\n email: List[NameEmail] # Supports both \"user@example.com\" and \"Name <user@example.com>\" formats\n\n\nconf = ConnectionConfig(\n MAIL_USERNAME =\"username\",\n MAIL_PASSWORD = \"**********\",\n MAIL_FROM = \"test@email.com\",\n MAIL_PORT = 465,\n MAIL_SERVER = \"mail server\",\n MAIL_STARTTLS = False,\n MAIL_SSL_TLS = True,\n USE_CREDENTIALS = True,\n VALIDATE_CERTS = True\n)\n\napp = FastAPI()\n\n\nhtml = \"\"\"\n<p>Thanks for using Fastapi-mail</p> \n\"\"\"\n\n\n@app.post(\"/email\")\nasync def simple_send(email: EmailSchema) -> JSONResponse:\n\n message = MessageSchema(\n subject=\"Fastapi-Mail module\",\n recipients=email.dict().get(\"email\"), # Can include \"Name <email@domain.com>\" format\n body=html,\n subtype=MessageType.html)\n\n fm = FastMail(conf)\n await fm.send_message(message)\n return JSONResponse(status_code=200, content={\"message\": \"email has been sent\"}) \n```\n\n## List of Examples\n\nFor more examples of using fastapi-mail please check: \n[example](https://sabuhish.github.io/fastapi-mail/example/) section.\n\n\n## Contributors \u2728\n\nThanks goes to these wonderful\n[People](https://github.com/sabuhish/fastapi-mail/blob/master/contributors.txt)\n\n\n# Contributing\nContributions of any kind are welcome!\n\nBefore you start, please read [CONTRIBUTING](https://github.com/sabuhish/fastapi-mail/blob/master/CONTRIBUTING.md)\n\n\n## LICENSE\n\n[MIT](LICENSE)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Simple lightweight mail library for FastApi",
"version": "1.5.7",
"project_urls": {
"Homepage": "https://github.com/sabuhish/fastapi-mail",
"Repository": "https://github.com/sabuhish/fastapi-mail"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2cb01ed51c03b0549e908376c684264a25db4e968a1d81963625aef62d177fba",
"md5": "f6109c03dc2eee41d99453b8943c7831",
"sha256": "7e6aee08de1dfd6c752792bdb4eb2912ffae15857d626c88f522ae47cbd2992b"
},
"downloads": -1,
"filename": "fastapi_mail-1.5.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f6109c03dc2eee41d99453b8943c7831",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0.0,>=3.10.0",
"size": 15390,
"upload_time": "2025-10-20T10:18:50",
"upload_time_iso_8601": "2025-10-20T10:18:50.745767Z",
"url": "https://files.pythonhosted.org/packages/2c/b0/1ed51c03b0549e908376c684264a25db4e968a1d81963625aef62d177fba/fastapi_mail-1.5.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5e07d067c5cd91313d17de7c582e7eb3851c83a0291491871b3c338cb48d19f6",
"md5": "42243c3e059e8c28cd4fcbacb1951597",
"sha256": "02df862ba56a67adca01eb22c8c1d62bd824051c0198e0eca91a0f4e7b636dc0"
},
"downloads": -1,
"filename": "fastapi_mail-1.5.7.tar.gz",
"has_sig": false,
"md5_digest": "42243c3e059e8c28cd4fcbacb1951597",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0.0,>=3.10.0",
"size": 13539,
"upload_time": "2025-10-20T10:18:52",
"upload_time_iso_8601": "2025-10-20T10:18:52.080611Z",
"url": "https://files.pythonhosted.org/packages/5e/07/d067c5cd91313d17de7c582e7eb3851c83a0291491871b3c338cb48d19f6/fastapi_mail-1.5.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-20 10:18:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sabuhish",
"github_project": "fastapi-mail",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "fastapi-mail"
}