Mail — Aquilia Documentation
Comprehensive guide and documentation for Mail in the Aquilia framework. View API reference, examples, and implementation patterns.
Advanced / Mail Mail System Overview AquilaMail is a production-ready mail dispatching subsystem featuring pluggable providers (SMTP, AWS SES, SendGrid), DKIM signing, automatic rate limiting, retry backoffs, and an integrated testing outbox. System Integration & Registration To enable email operations, declare the Mail integration at the workspace level, configure templates, and inject the service into your module endpoints. 1. Workspace Integration Register Mail in workspace.py using MailIntegration : from aquilia.workspace import Workspace from aquilia.integrations import MailIntegration, SmtpProvider, MailAuth workspace = ( Workspace("myapp") .integrate(MailIntegration( default_from="noreply@myapp.com", subject_prefix="[MyApp] ", auth=MailAuth.plain("smtp_user", password_env="SMTP_PASSWORD"), providers=[ SmtpProvider(host="smtp.sendgrid.net", port=587, use_tls=True) ], rate_limit_global=1000, dkim_enabled=False )) ) 2. Injecting Mail Service in Modules Inject MailService directly into controllers or services to access the sending APIs: from aquilia import Controller, Post, Inject from aquilia.mail import MailService, TemplateMessage class AuthController(Controller): prefix = "/auth" @Inject() def __init__(self, mail: MailService): self.mail = mail @Post("/notify") async def notify(self, ctx): msg = TemplateMessage( template="alert.aqt", context= , subject="Security Alert", to=[ctx.identity.email] ) await msg.asend() return ctx.json( ) Core Mail Architectures , , , ].map((item, i) => ( ))} Testing Outbox Assertions During testing, the mail system captures outbound emails into an in-memory outbox list rather than dispatching them to external SMTP servers: from aquilia.testing import AquiliaTestCase, MailTestMixin class RegistrationTestCase(AquiliaTestCase, MailTestMixin): async def test_registration_welcomes(self): await self.client.post("/auth/register") # Verify that exactly one email was sent self.assert_mail_sent(count=1) # Pull the message from outbox and assert properties sent_msg = self.get_sent_mail()[0] assert sent_msg.to == "user@example.com" assert "Welcome!" in sent_msg.subject Security MailService )
Go to Homepage