FastAPI
Learn how to integrate Mailtrap with FastAPI to send emails via Email API.
Send emails using FastAPI and Mailtrap
import mailtrap as mt
from typing import Dict
from fastapi import FastAPI
app = FastAPI()
@app.post("/")
def send_mail() -> Dict:
mail = mt.Mail(
sender=mt.Address(email="YOUR-EMAIL-HERE", name="Mailtrap Test"),
to=[mt.Address(email="RECIPIENT-EMAIL-HERE")],
subject="Hello World",
html="<strong>it works!</strong>",
)
client = mt.MailtrapClient(token="YOUR-MAILTRAP-API-KEY-HERE")
response = client.send(mail)
return responseLast updated
Was this helpful?

