Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: async support #92

Open
wolfskaempf opened this issue Mar 21, 2024 · 0 comments
Open

ENH: async support #92

wolfskaempf opened this issue Mar 21, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@wolfskaempf
Copy link

Is your feature request related to a problem? Please describe.
I'm considering using red-mail to send emails in a backend application. Since connecting to the SMTP server is an I/O blocking operation, I would like to make use of async to avoid blocking other requests while the SMTP server or network are slow.

Describe the solution you'd like
I would like to be able to use red-mail in the following way.

from redmail import EmailSender
from fastapi import FastAPI

app = FastAPI()

@app.post("/send-email")
async def send_email() -> dict[str, str]:
    """Send an example email when this API endpoint is requested."""
    
    email = EmailSender(host='localhost', port=0)  # Real SMTP server would be on a remote network
    
    # By awaiting here, we allow other requests to be processed while waiting for I/O
    # Of course, using a different method name like `asend` would also be fine in order to keep the synchronous methods backwards compatible
    await email.send(  
        subject='async support in red-mail',
        sender="[email protected]",
        receivers=['[email protected]']
    )

    return {"status": "OK"}

Describe alternatives you've considered
Without async support I'd have to introduce additional complexity to get the same results.

  • manually creating threads or processes
  • fork red-mail and make it async
  • introduce a task queue and hand over email sending tasks

@Miksus If you're open to this, please let me know :) Thank you!

@wolfskaempf wolfskaempf added the enhancement New feature or request label Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant