Skip to content

Repository files navigation

Fastapi-mail

Simple lightweight mail system for FastAPI — send emails, attachments, and HTML templates.

MIT licensedGitHub starsGitHub issuesDownloads

Documentation: sabuhish.github.io/fastapi-mail


Installation

pip install fastapi-mail

Quick Start

fromtypingimportListfromfastapiimportFastAPIfromfastapi_mailimportConnectionConfig, FastMail, MessageSchema, MessageType, NameEmailfrompydanticimportBaseModelfromstarlette.responsesimportJSONResponseclassEmailSchema(BaseModel):
email: List[NameEmail]
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()
@app.post("/email")asyncdefsimple_send(email: EmailSchema) ->JSONResponse:
message=MessageSchema(
subject="Fastapi-Mail module",
recipients=email.model_dump().get("email"),
body="<p>Thanks for using Fastapi-mail</p>",
subtype=MessageType.html,
)
awaitFastMail(conf).send_message(message)
returnJSONResponse(status_code=200, content={"message": "email has been sent"})

Contributing

Contributions of any kind are welcome! Please read CONTRIBUTING before you start.

Contributors

Thanks goes to these wonderful people.

LICENSE

MIT

About

Fastapi mail system sending mails(individual, bulk) attachments(individual, bulk)

Topics

Resources

Contributing

Stars

1.0k stars

Watchers

13 watching

Forks

Releases

Packages

Used by

Contributors

Languages