Handling Per-Tenant SMTP Settings

I’m building a multi-tenant app and each tenant needs to use their own SMTP credentials for sending emails (like what’s usually configured in the .env file). What’s the best practice or cleanest way to handle this?
4 Replies
dannyduberstein
dannyduberstein2mo ago
I think most importantly just remember to hash the credentials when storing in a database, don't leave the SMTP details out in the open. Assuming you have auth credentials stored per tenant. For multi-tenancy and if you're just doing a nice clean approach with multiple tenants on a single database, then you need to ensure every query is globally scoped to include the tenant_id to ensure you only ever return information for that. https://laravel.com/docs/12.x/eloquent#query-scopes
dannyduberstein
dannyduberstein2mo ago
https://filamentphp.com/docs/4.x/users/tenancy#simple-one-to-many-tenancy You should have a read of this too. As mentioned Filament's tenancy system assumes many users belong to many tenants. I think most use cases are actually 1 tenant has many users. and user can only belong to 1 tenant. Depends!
Marketer
MarketerOP2mo ago
I've built the application, and now I need to integrate the SMTP part. Could you suggest the best email client, assuming a sending volume of 6,000 emails per day per tenant?
dannyduberstein
dannyduberstein2mo ago
6000 emails..Well Use something like SES Or a transactional email provider? postmark, sendgrid, mailgun Depending on how many tenants you have you are arleady close to 200K emails per month, could be looking at ~$400 USD per month minimum if you had 3 tenants

Did you find this page helpful?