Giter Site home page Giter Site logo

marktennyson / fastapi-mailman Goto Github PK

View Code? Open in Web Editor NEW
19.0 1.0 7.0 752 KB

Porting Django's email implementation to your FastAPI applications.

Home Page: http://gh.aniketsarkar.site/fastapi-mailman/

License: MIT License

Python 99.13% Makefile 0.87%
fastapi-mail fastapi fastapi-framework fastapi-mailman smtp fastapi-smtp fastapi-extension fastapi-library

fastapi-mailman's Introduction

๐Ÿ“ฌ Fastapi-Mailman

๐Ÿ”ฅ Porting Django's email implementation to your FastAPI applications.

PyPI PyPI - Downloads dev workflow GitHub commits since latest release (by SemVer) PyPI - License

Fastapi-Mailman is a Fastapi extension providing simple email sending capabilities. It's actually a hard fork of waynerv's flask-mailman module. I have tried to implement the same features for the Fastapi too.

It was meant to replace the basic Fastapi-Mail with a better warranty and more features.

โ›ฒ Key Features:

  1. Easy to use.
  2. Backend based email sender.
  3. Customisable backend class.
  4. Proper testcases.
  5. Proper documentation.

๐Ÿ”— Important Links:

Github Repo
PYPI
Documentation

๐Ÿ’ฏ Usage

Fastapi-Mailman ported Django's email implementation to your Fastapi applications, which may be the best mail sending implementation that's available for python.

The way of using this extension is almost the same as Django.

Documentation: https://marktennyson.github.io/fastapi-mailman.

๐Ÿชœ Basic Example

from fastapi import FastAPI
import uvicorn as uv
from fastapi_mailman import Mail, EmailMessage
from fastapi_mailman.config import ConnectionConfig

app = FastAPI(debug=True)

config = config = ConnectionConfig(
    MAIL_USERNAME = '[email protected]',
    MAIL_PASSWORD = "7655tgrf443%$",
    MAIL_BACKEND =  'smtp',
    MAIL_SERVER =  'smtp.gmail.com',
    MAIL_PORT = 587,
    MAIL_USE_TLS = True,
    MAIL_USE_SSL = False,
    MAIL_DEFAULT_SENDER = '[email protected]',
    )
mail = Mail(config)

@app.get("/send-base")
async def send_base():
    msg = EmailMessage('this is subject', 'this is message', to=['[email protected]'])
    await msg.send()
    return {"Hello": "World"}

@app.get("/send-mail")
async def check_send_mail():
    await mail.send_mail("this is subject", "this is message", None, ["[email protected]"])
    return {"Hello": "World"}


if __name__ == "__main__":
    uv.run(app, port=8082, debug=True)

๐Ÿš‡ Development

๐Ÿง‘โ€๐Ÿ’ป Contribution procedure.

  1. Create a new issue on github.
  2. Fork and clone this repository.
  3. Make some changes as required.
  4. Write unit test to showcase its functionality.
  5. Submit a pull request under the master branch.

๐Ÿ–จ๏ธ Run this project on your local machine.

To run this project on your local machine please click here

โค๏ธ Contributors

Credits goes to these peoples:

๐Ÿ“ License

MIT

Copyright (c) 2021 Aniket Sarkar([email protected])

fastapi-mailman's People

Contributors

daniel-herrero avatar marktennyson avatar yezz123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

fastapi-mailman's Issues

Update fastapi-mailman dependencies

Is your feature request related to a problem? Please describe.

I am currently running FastAPI 0.73.0 (with in turn uses Starlette 0.17.1), but Fastapi-Mailman requires to run FastAPI 0.68.2 (and Starlette 0.14.2).

I believe that outdated version of Starlette make some tests to fail with the following error in the testclient.py:

>       response = client.post("/auth/token", json=data)

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../.venv/lib/python3.10/site-packages/requests/sessions.py:577: in post

../../.venv/lib/python3.10/site-packages/requests/sessions.py:577: in post
    return self.request('POST', url, data=data, json=json, **kwargs)
../../.venv/lib/python3.10/site-packages/starlette/testclient.py:415: in request
    return super().request(
../../.venv/lib/python3.10/site-packages/requests/sessions.py:529: in request
    resp = self.send(prep, **send_kwargs)
../../.venv/lib/python3.10/site-packages/requests/sessions.py:645: in send
    r = adapter.send(request, **kwargs)
../../.venv/lib/python3.10/site-packages/starlette/testclient.py:243: in send
    raise exc from None
../../.venv/lib/python3.10/site-packages/starlette/testclient.py:240: in send
    loop.run_until_complete(self.app(scope, receive, send))
/home/daniel/.pyenv/versions/3.10.2/lib/python3.10/asyncio/base_events.py:617: in run_until_complete
    self._check_running()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <_UnixSelectorEventLoop running=False closed=False debug=False>

    def _check_running(self):
        if self.is_running():
>           raise RuntimeError('This event loop is already running')
E           RuntimeError: This event loop is already running

/home/daniel/.pyenv/versions/3.10.2/lib/python3.10/asyncio/base_events.py:577: RuntimeError
----------------------------------------------------------------------------------- Captured stderr setup ------------------------------------------------------------------------------------
Got an error creating the test database: database "test" already exists

================================================================================== short test summary info ===================================================================================
FAILED tests/auth/test_api.py::test_login_successfully - RuntimeError: This event loop is already running

Describe the solution you'd like

Try to unset the fixed versions from the dependencies (pyproject.toml) to evaluate if there's (or not) a real problem when using the last available versions.

[tool.poetry.dependencies]
python = "^3.6.2"
fastapi = "^0.68.1"
Jinja2 = "^3.0.1"
aiosmtplib = "^1.1.6"
pydantic = "^1.8.2"
email-validator = "^1.1.3"
dnspython = "^2.1.0"

In case of an error, try to locate and find a fix for the conflicting code.

Describe alternatives you've considered

A partial solution would be to update part of the dependencies to their last unaffected versions (in an error case scenario).

Additional context

Using Python 3.10.2

Built-in support for Mailgun

Is your feature request related to a problem? Please describe.
At Tacto we are looking for a drop-in replacement of django-anymail but in FastAPI, that supports Mailgun, our third-party service. We're migration from Django to FastAPI for our API.

Describe the solution you'd like
Ideally, we want to be able to swap backends, like SMTP or Mailgun, but we might as well switch to a different provider in the future. So we want this to be easy.

What I like is that this project supports backends. However, I wonder what are your thoughts on supporting third-party backends, the same way django-anymail does. We oould provide an implementation of a Mailgun backend, heavily based on https://github.com/anymail/django-anymail/blob/main/anymail/backends/mailgun.py.

Describe alternatives you've considered
Alternatively, if you want to keep this project provider-agnostic, we could implement the Mailgun backend as a separate plugin. We would need a way to support external plugins.

Additional context
Add any other context or screenshots about the feature request here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.