Simple lightwigh mail sending for FastApi
Project description
Fastapi-mail
Fastapi with fastapi-mail simple lightweight
Fastapi mail system sending mails(individual, bulk) attachments(individual, bulk)
Thanks to for creating awesome framework!
Installation
$ pip install fastapi-mail
Email Send example
from fastapi import FastAPI
from starlette.responses import JSONResponse
from fastapi_mail import FastMail
from starlette.background import BackgroundTask
from test_examples.templates import html, backgorund_task,bulkmail
from fastapi import File, Body,Query, UploadFile
app = FastAPI()
#test email standart sending mail
@app.post("/email")
async def my_awesome_func_1(email: dict= Body(...)) -> JSONResponse:
email = email.get("email")
mail = FastMail("your_account@gmail.com","*********",tls=True)
await mail.send_message(email,"Test email from fastapi-mail", html, text_format="html")
return JSONResponse(status_code=200, content={"message": f"email has been sent {email} address"})
#this mail sending using starlettes background tasks, faster than the above one
@app.post("/emailbackground")
async def my_awesome_func_2(email: dict= Body(...)) -> JSONResponse:
email = email.get("email")
mail = FastMail("your_account@gmail.com","*********",tls=True)
task = BackgroundTask(mail.send_message, email,"Test email from fastapi-mail with background task",backgorund_task,text_format="html")
return JSONResponse(status_code=200,
content={"message": f"email has been sent {email} address"},
background=task)
#this an example of sending bulk mails
@app.post("/bulkemail")
async def my_awesome_func_3() -> JSONResponse:
email = ["sabuhi.shukurov@gmail.com","sabus02@gmail.com"]
mail = FastMail("your_account@gmail.com","*********",tls=True)
task = BackgroundTask(mail.send_message, email,"Bulk mail from fastapi-mail with background task","Bulk mail Test",text_format="plain",bulk=True)
return JSONResponse(status_code=200, content={"message": f"email has been sent to these {email} addresses"}, background=task)
#an example of sending bulk mails attaching files
@app.post("/bulkfile")
async def my_awesome_func_4(file: UploadFile = File(...), file2: UploadFile = File(...)) -> JSONResponse:
email = ["someaddress@gmail.com","address2@gmail.com"]
mail = FastMail("your_account@gmail.com","*********",tls=True)
task = BackgroundTask(mail.send_message, email,"Bulk mail from fastapi-mail with background task","Bulk mail Test",text_format="plain",bulk=True,file=[file,file2])
return JSONResponse(status_code=200, content={"message": f"email has been sent to these {email} addresses"}, background=task)
Contributing
Fell free to open issue and send pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi-mail-0.1.2.tar.gz
(4.5 kB
view details)
Built Distribution
File details
Details for the file fastapi-mail-0.1.2.tar.gz
.
File metadata
- Download URL: fastapi-mail-0.1.2.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08918705a92d88ec66059a7c536adb4601aabee24178d8d87023a26de21cdf6e |
|
MD5 | e2586284a89006695aaf1dd49b09f5dc |
|
BLAKE2b-256 | d1d413e76165e520b0b6643d3602868f73fd6ce36398f585a11258f1f9aecf53 |
File details
Details for the file fastapi_mail-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: fastapi_mail-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d514e32c7075aa9ead7d0ffa7e15359d7a8bb55eb8b0c69540f840ebebfb1cc0 |
|
MD5 | 07574062519702ed10845464a903df8e |
|
BLAKE2b-256 | 1a0f2e429ca6608c96888a9e2560316601ad179339e7d652f92535a22447b807 |