diff --git a/.env.example b/.env.example index 9e97a2c..e823dea 100644 --- a/.env.example +++ b/.env.example @@ -19,4 +19,8 @@ SMTP_USER=your-smtp-user@example.com SMTP_PASS=your-smtp-password # The recipient for booking messages (defaults to christian@warme.dk) -BOOKING_EMAIL=christian@warme.dk \ No newline at end of file +BOOKING_EMAIL=christian@warme.dk +SENDER_EMAIL=christian@warme.dk + +# Notes: If your account uses MFA, create an app password for SMTP and use it in SMTP_PASS. +# Office365 settings: SMTP_HOST=smtp.office365.com, SMTP_PORT=587 (STARTTLS) \ No newline at end of file diff --git a/README.md b/README.md index a4259bc..f6d18c2 100644 --- a/README.md +++ b/README.md @@ -80,3 +80,25 @@ Notes: - Generated images can be large; a small number of generated images were removed from git and the project ignores `public/img/generated/`. If you want generated images checked into the repo, move them into `public/img/` and commit explicitly. - For production process management the project includes PM2 scripts in `package.json` (see `pm2:*` scripts). +### Office365 / SMTP (app password) + +If you plan to use an Office365 mailbox with SMTP (app password): + +1. Enable SMTP AUTH for the mailbox (tenant settings may block it by default). +2. If the mailbox has MFA enabled, create an app password for the mailbox and use it as `SMTP_PASS`. + - Microsoft 365: My account -> Security info -> Add method -> App password (or use admin center to manage). +3. Set these env vars in your local `.env`: + +```bash +SMTP_HOST=smtp.office365.com +SMTP_PORT=587 +SMTP_USER=christian@warme.dk +SMTP_PASS=your-app-password +SENDER_EMAIL=christian@warme.dk +BOOKING_EMAIL=christian@warme.dk +``` + +4. The contact API will send mail using the authenticated mailbox as the From address and set Reply-To to the visitor's email so replies go to them. + +If you prefer a more modern and robust approach we can switch to Microsoft Graph API with OAuth2 (recommended for production). + diff --git a/src/app/api/contact/route.ts b/src/app/api/contact/route.ts index 2067be0..d1b07e9 100644 --- a/src/app/api/contact/route.ts +++ b/src/app/api/contact/route.ts @@ -49,11 +49,18 @@ export async function POST(req: Request) {