Adds the complete Next.js website including i18n routing, house and apartment pages, Beds24 v2 integration for live availability/pricing, Stripe checkout, contact forms, Docker setup and deployment docs. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import nodemailer from "nodemailer";
|
|
|
|
export interface ContactMessage {
|
|
email: string;
|
|
message: string;
|
|
name?: string;
|
|
/** Optional context, e.g. the search dates that had no availability. */
|
|
context?: string;
|
|
}
|
|
|
|
function getTransport() {
|
|
const { SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD } = process.env;
|
|
if (!SMTP_HOST || !SMTP_USER || !SMTP_PASSWORD) {
|
|
return null;
|
|
}
|
|
|
|
return nodemailer.createTransport({
|
|
host: SMTP_HOST,
|
|
port: Number(SMTP_PORT) || 587,
|
|
secure: Number(SMTP_PORT) === 465,
|
|
auth: {
|
|
user: SMTP_USER,
|
|
pass: SMTP_PASSWORD,
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function sendContactMessage(data: ContactMessage): Promise<void> {
|
|
const transport = getTransport();
|
|
const to = process.env.CONTACT_INBOX_EMAIL || "info@bb-apartment.de";
|
|
const from = process.env.SMTP_FROM || "noreply@bb-apartment.de";
|
|
|
|
const subject = `Neue Kontaktanfrage von ${data.name || data.email}`;
|
|
const text = [
|
|
data.context ? `Kontext: ${data.context}` : null,
|
|
`Name: ${data.name || "-"}`,
|
|
`E-Mail: ${data.email}`,
|
|
"",
|
|
data.message,
|
|
]
|
|
.filter(Boolean)
|
|
.join("\n");
|
|
|
|
if (!transport) {
|
|
// No SMTP configured yet (development) — log instead of failing so the
|
|
// form still "works" locally.
|
|
console.log("[contact] SMTP not configured, would have sent:", {
|
|
to,
|
|
from,
|
|
subject,
|
|
text,
|
|
});
|
|
return;
|
|
}
|
|
|
|
await transport.sendMail({
|
|
to,
|
|
from,
|
|
replyTo: data.email,
|
|
subject,
|
|
text,
|
|
});
|
|
}
|