#!/usr/bin/env node /** * Test Geofence Email Notification * * This script sends a test email notification for a geofence event * without needing the full MQTT/Next.js server stack. */ const nodemailer = require('nodemailer'); const { render } = require('@react-email/components'); console.log('πŸ“§ Geofence Email Notification Test\n'); // SMTP configuration from .env const SMTP_CONFIG = { host: process.env.SMTP_HOST || 'smtp-relay.brevo.com', port: parseInt(process.env.SMTP_PORT || '587', 10), secure: process.env.SMTP_SECURE === 'true', auth: { user: process.env.SMTP_USER || 'joachim.hummel@gmail.com', pass: process.env.SMTP_PASS || 'xqwXW2Sr3ZNcITa1', }, }; const FROM_EMAIL = process.env.SMTP_FROM_EMAIL || 'noreply@businesshelpdesk.biz.com'; const FROM_NAME = process.env.SMTP_FROM_NAME || 'Location Tracker'; const TO_EMAIL = 'joachim.hummel@gmail.com'; async function sendTestEmail() { try { console.log('πŸ”§ Step 1: Creating SMTP transporter...'); console.log(` Host: ${SMTP_CONFIG.host}:${SMTP_CONFIG.port}`); console.log(` From: ${FROM_NAME} <${FROM_EMAIL}>`); console.log(` To: ${TO_EMAIL}\n`); const transporter = nodemailer.createTransport(SMTP_CONFIG); // Test connection console.log('πŸ”Œ Step 2: Testing SMTP connection...'); await transporter.verify(); console.log('βœ“ SMTP connection successful!\n'); // Prepare email content console.log('πŸ“ Step 3: Preparing email...'); const emailData = { username: 'Admin', deviceName: 'Device A', geofenceName: 'Test Zone', timestamp: new Date().toISOString(), latitude: 50.1109, longitude: 8.6821, distanceFromCenter: 0, }; // Simple HTML email (since we can't easily import React Email in this context) const html = ` Geofence Benachrichtigung

Geofence Benachrichtigung

Hallo ${emailData.username},

Ihr GerΓ€t "${emailData.deviceName}" hat die Zone "${emailData.geofenceName}" betreten.

Details:

Zeit: ${new Date(emailData.timestamp).toLocaleString('de-DE')}

Position: ${emailData.latitude}, ${emailData.longitude}

Distanz vom Zentrum: ${emailData.distanceFromCenter} Meter

Diese Benachrichtigung wurde automatisch von Ihrem Location Tracker System gesendet.

Location Tracker Β© ${new Date().getFullYear()}

`; console.log('βœ“ Email prepared\n'); // Send email console.log('πŸ“€ Step 4: Sending email...'); const info = await transporter.sendMail({ from: `"${FROM_NAME}" <${FROM_EMAIL}>`, to: TO_EMAIL, subject: `${emailData.deviceName} hat ${emailData.geofenceName} betreten`, html: html, }); console.log('βœ… Email sent successfully!\n'); console.log('πŸ“¬ Details:'); console.log(` Message ID: ${info.messageId}`); console.log(` Response: ${info.response}\n`); console.log('πŸ’‘ Check your inbox at: ' + TO_EMAIL); console.log(' (May take a few seconds to arrive)'); } catch (error) { console.error('\n❌ Failed to send email:', error.message); if (error.code === 'EAUTH') { console.error('\nπŸ’‘ Authentication failed. Check your SMTP credentials in .env'); } else if (error.code === 'ETIMEDOUT' || error.code === 'ECONNECTION') { console.error('\nπŸ’‘ Connection timeout. Check your SMTP host and port.'); } process.exit(1); } } // Run test console.log('Starting email notification test...\n'); sendTestEmail().then(() => { console.log('\nβœ… Test completed!'); process.exit(0); }).catch((error) => { console.error('Unexpected error:', error); process.exit(1); });