# Portal-aware email sender identity

## Purpose

One Laravel application and one SMTP transport may serve both products, while
each outbound email uses the sender identity of the portal workflow that
created it. The application does not infer the sender from an arbitrary
queued-job request host.

| Portal | Sender identity | Portal URL |
| --- | --- | --- |
| TakafulHub | `TakafulHub <noreply@takafulhub.io>` | `https://app.takafulhub.io` |
| VastPro | `VastPro <noreply@vastpro.app>` | `https://vastpro.app` |

The defaults above are development-safe identity defaults. They do not
configure SMTP delivery. Production SMTP credentials remain environment-only
deployment configuration.

## Configuration

Set one standard Laravel mail transport (`MAIL_MAILER`, `MAIL_HOST`,
`MAIL_PORT`, `MAIL_USERNAME`, `MAIL_PASSWORD`, and encryption settings) and
configure sender identities separately:

```dotenv
MAIL_FROM_ADDRESS=noreply@takafulhub.io
MAIL_FROM_NAME=TakafulHub
VASTPRO_MAIL_FROM_ADDRESS=noreply@vastpro.app
VASTPRO_MAIL_FROM_NAME=VastPro
```

Both From domains must be valid for the selected SMTP provider. Configure the
provider's SPF/DKIM/DMARC requirements before enabling delivery. Do not put
credentials in source control, test fixtures, client code, or this document.

## Trusted portal selection and queue safety

`PortalContextResolver` maps only configured allow-listed hosts to a
`PortalType`. Unknown hosts resolve to the public context, while the sender
resolver maps public and Sites contexts to the TakafulHub identity. A caller
cannot select VastPro by providing a host-like string. `PortalMailContext`
snapshots that trusted enum during verification/reset dispatch. Operational
notifications already carry their `portal` value in the serialized payload.

`PortalMailIdentityResolver` uses that enum to select configuration and fails
closed if the address or brand is invalid. The queue worker resolves the
serialized portal value, not a future worker/request host.

## Covered email paths

- TakafulHub registration verification: TakafulHub identity.
- Password reset from `app.takafulhub.io` or `vastpro.app`: matching portal
  identity and matching reset link host.
- VastPro approval/status, support replies, lead, membership, affiliate,
  partner, rank and credit operational notifications: portal supplied by the
  notification delivery service and preserved for queued delivery.
- TakafulHub registration approval/rejection mailables: explicit TakafulHub
  identity.

VastPro's current pre-approval registration flow does not create a login user,
so it does not send a verification email at that stage. Its approved-user
operational notifications use the VastPro identity.

Sites management and public legal pages do not have an outbound email
workflow. They do not receive website header code and do not select a mail
sender.

## Operations

Keep the Laravel queue worker running before switching `MAIL_MAILER` away from
`log`. Queue failures use the existing retry/backoff policy and produce a
warning with notification key/user/dedupe metadata only; no sensitive content
is logged. Retry failed jobs through the normal Laravel queue workflow after
the mail provider issue is corrected.

Staging verification should use mailbox-controlled addresses and verify both
From identities, Reply-To policy (if configured by the provider), action-link
hosts, SPF/DKIM alignment, and queue retry behaviour. No production email is
sent by automated regression tests.
