docs: update Mailgun configuration with correct sandbox domain
- Update domain to sandbox1835a1917b07443f8c1ca858689c42ea.mailgun.org - Set test email to psbailey31@gmail.com - Add comprehensive Mailgun setup guide - Document sandbox authorization requirements - Create email testing script - Update troubleshooting documentation Note: Sandbox domains require recipient authorization in Mailgun dashboard
This commit is contained in:
62
server/src/scripts/testEmail.ts
Normal file
62
server/src/scripts/testEmail.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Quick test script for email service
|
||||
*/
|
||||
|
||||
import dotenv from 'dotenv';
|
||||
import { emailService } from '../services/emailService';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
async function testEmail() {
|
||||
console.log('📧 Testing Email Service with Mailgun\n');
|
||||
|
||||
console.log('Configuration:');
|
||||
console.log(` API Key: ${process.env.MAILGUN_API_KEY?.substring(0, 20)}...`);
|
||||
console.log(` Domain: ${process.env.MAILGUN_DOMAIN}`);
|
||||
console.log(` From: ${process.env.FROM_EMAIL}`);
|
||||
console.log('');
|
||||
|
||||
// Test 1: Send a simple test email
|
||||
console.log('1️⃣ Sending test email...');
|
||||
const testEmail = process.env.TEST_EMAIL || 'psbailey31@gmail.com';
|
||||
|
||||
const success = await emailService.sendEmail({
|
||||
to: testEmail,
|
||||
subject: 'Beach Litter Platform - Test Email',
|
||||
text: 'This is a test email from the Beach Litter Mapping Platform. If you received this, email notifications are working correctly!',
|
||||
});
|
||||
|
||||
if (success) {
|
||||
console.log(`✅ Test email sent successfully to ${testEmail}`);
|
||||
console.log(' Check your inbox (and spam folder)');
|
||||
} else {
|
||||
console.log(`❌ Failed to send test email to ${testEmail}`);
|
||||
}
|
||||
console.log('');
|
||||
|
||||
// Test 2: Send a formatted notification email
|
||||
console.log('2️⃣ Sending formatted notification email...');
|
||||
const notificationSuccess = await emailService.sendNotificationEmail(
|
||||
testEmail,
|
||||
'Test User',
|
||||
'New Litter Report in Your Area',
|
||||
'A new plastic litter report was submitted near Dublin city center. The report indicates a significant amount of plastic waste.',
|
||||
'report',
|
||||
'test-report-123'
|
||||
);
|
||||
|
||||
if (notificationSuccess) {
|
||||
console.log(`✅ Notification email sent successfully to ${testEmail}`);
|
||||
console.log(' Check your inbox for a formatted notification');
|
||||
} else {
|
||||
console.log(`❌ Failed to send notification email to ${testEmail}`);
|
||||
}
|
||||
console.log('');
|
||||
|
||||
console.log('✅ Email testing completed!');
|
||||
console.log('');
|
||||
console.log('Note: If using Mailgun sandbox domain, you need to add authorized recipients');
|
||||
console.log('in your Mailgun dashboard: https://app.mailgun.com/');
|
||||
}
|
||||
|
||||
testEmail().catch(console.error);
|
||||
@@ -9,7 +9,7 @@ const mg = mailgun.client({
|
||||
key: process.env.MAILGUN_API_KEY || 'dd27be7a81dd7b0980ada31fec9a9bd9-e80d8b76-fd80c63b',
|
||||
});
|
||||
|
||||
const MAILGUN_DOMAIN = process.env.MAILGUN_DOMAIN || 'sandbox-123.mailgun.org';
|
||||
const MAILGUN_DOMAIN = process.env.MAILGUN_DOMAIN || 'sandbox1835a1917b07443f8c1ca858689c42ea.mailgun.org';
|
||||
const FROM_EMAIL = process.env.FROM_EMAIL || 'Beach Litter Platform <noreply@beachlitter.ie>';
|
||||
|
||||
interface EmailData {
|
||||
|
||||
Reference in New Issue
Block a user