# 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
- 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
from pydantic import BaseModel, EmailStr
from starlette.responses import JSONResponse
class EmailSchema(BaseModel):
email: List[EmailStr]
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"),
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,>=3.8.1",
"maintainer_email": null,
"keywords": null,
"author": "Sabuhi Shukurov",
"author_email": "sabuhi.shukurov@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/b5/2b/a743bd324d640201c3ce2dcea4acb143058926ed3e7bfbea08304075b5c5/fastapi_mail-1.4.2.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- 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\nfrom pydantic import BaseModel, EmailStr\nfrom starlette.responses import JSONResponse\n\n\n\nclass EmailSchema(BaseModel):\n email: List[EmailStr]\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\"),\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.4.2",
"project_urls": {
"Homepage": "https://github.com/sabuhish/fastapi-mail",
"Repository": "https://github.com/sabuhish/fastapi-mail"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ddee5d154eb4621d6a037e139a32bc1244ba8cb78a7aca9d438b56e24552203c",
"md5": "da09fd35df1d57f21dcd15e56018af21",
"sha256": "3525cf342ff91f6bcb3298570d1783498082e586957f668ee4164a0aab6ec743"
},
"downloads": -1,
"filename": "fastapi_mail-1.4.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "da09fd35df1d57f21dcd15e56018af21",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8.1",
"size": 14748,
"upload_time": "2024-11-23T12:06:26",
"upload_time_iso_8601": "2024-11-23T12:06:26.127842Z",
"url": "https://files.pythonhosted.org/packages/dd/ee/5d154eb4621d6a037e139a32bc1244ba8cb78a7aca9d438b56e24552203c/fastapi_mail-1.4.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b52ba743bd324d640201c3ce2dcea4acb143058926ed3e7bfbea08304075b5c5",
"md5": "b86c50623a2ae3218891dde044f9924b",
"sha256": "04bde1005c624f42dfc0a9c1e313fcc544499fdd6b3531e606c500d80ac2ffcb"
},
"downloads": -1,
"filename": "fastapi_mail-1.4.2.tar.gz",
"has_sig": false,
"md5_digest": "b86c50623a2ae3218891dde044f9924b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8.1",
"size": 13353,
"upload_time": "2024-11-23T12:06:27",
"upload_time_iso_8601": "2024-11-23T12:06:27.880653Z",
"url": "https://files.pythonhosted.org/packages/b5/2b/a743bd324d640201c3ce2dcea4acb143058926ed3e7bfbea08304075b5c5/fastapi_mail-1.4.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-23 12:06:27",
"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"
}