Remove email testing scripts and related files to streamline the project. This includes the deletion of various SMTP test scripts, contact form tests, and associated HTML files, which were previously used for testing email delivery and configuration.
This commit is contained in:
41
.github/workflows/actions.yaml
vendored
41
.github/workflows/actions.yaml
vendored
@@ -1,41 +0,0 @@
|
||||
name: GitHub Actions
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version:
|
||||
- 18
|
||||
- 20
|
||||
- 22
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Use Node.js v${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: npm
|
||||
- run: npm ci
|
||||
- run: npm run build
|
||||
# - run: npm test
|
||||
|
||||
check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Use Node.js 22
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
cache: npm
|
||||
- run: npm ci
|
||||
- run: npm run check
|
@@ -1,137 +0,0 @@
|
||||
/**
|
||||
* Email Delivery Test Script
|
||||
*
|
||||
* This script tests email delivery by sending test emails to different addresses
|
||||
* and with different configurations to help diagnose delivery issues.
|
||||
*/
|
||||
|
||||
const nodemailer = require('nodemailer');
|
||||
require('dotenv').config();
|
||||
|
||||
// Environment variables
|
||||
const {
|
||||
SMTP_HOST = 'smtp.protonmail.ch',
|
||||
SMTP_PORT = '587',
|
||||
SMTP_USER = '',
|
||||
SMTP_PASS = '',
|
||||
ADMIN_EMAIL = 'richard@bergsma.it',
|
||||
WEBSITE_NAME = 'bergsma.it',
|
||||
NODE_ENV = 'development'
|
||||
} = process.env;
|
||||
|
||||
// Set to production mode for this test
|
||||
const isProduction = true;
|
||||
|
||||
console.log('Email Delivery Test');
|
||||
console.log('------------------');
|
||||
console.log('Configuration:');
|
||||
console.log(`SMTP Host: ${SMTP_HOST}`);
|
||||
console.log(`SMTP Port: ${SMTP_PORT}`);
|
||||
console.log(`SMTP User: ${SMTP_USER}`);
|
||||
console.log(`Admin Email: ${ADMIN_EMAIL}`);
|
||||
console.log(`Website Name: ${WEBSITE_NAME}`);
|
||||
console.log(`Mode: ${isProduction ? 'production' : 'development'}`);
|
||||
console.log('------------------');
|
||||
|
||||
// Create a transporter
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: SMTP_HOST,
|
||||
port: parseInt(SMTP_PORT, 10),
|
||||
secure: parseInt(SMTP_PORT, 10) === 465,
|
||||
auth: {
|
||||
user: SMTP_USER,
|
||||
pass: SMTP_PASS,
|
||||
},
|
||||
tls: {
|
||||
rejectUnauthorized: false,
|
||||
ciphers: 'SSLv3'
|
||||
},
|
||||
debug: true
|
||||
});
|
||||
|
||||
// Verify connection
|
||||
console.log('Testing SMTP connection...');
|
||||
transporter.verify(function(error, success) {
|
||||
if (error) {
|
||||
console.error('SMTP Connection Error:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('SMTP Connection Successful!');
|
||||
runTests();
|
||||
});
|
||||
|
||||
// Run a series of email delivery tests
|
||||
async function runTests() {
|
||||
try {
|
||||
// Test 1: Basic email to admin
|
||||
console.log('\nTest 1: Sending basic email to admin...');
|
||||
await sendTestEmail(
|
||||
ADMIN_EMAIL,
|
||||
'Email Delivery Test 1 - Basic',
|
||||
'This is a basic test email to the admin address.',
|
||||
`<p>This is a basic test email to the admin address.</p><p>Time: ${new Date().toISOString()}</p>`
|
||||
);
|
||||
|
||||
// Test 2: Email with different From address
|
||||
console.log('\nTest 2: Sending email with different From address...');
|
||||
await sendTestEmail(
|
||||
ADMIN_EMAIL,
|
||||
'Email Delivery Test 2 - Different From',
|
||||
'This email uses a different From address.',
|
||||
`<p>This email uses a different From address.</p><p>Time: ${new Date().toISOString()}</p>`,
|
||||
`"Test Sender" <${SMTP_USER}>`
|
||||
);
|
||||
|
||||
// Test 3: Email with contact form format
|
||||
console.log('\nTest 3: Sending email in contact form format...');
|
||||
const contactFormHtml = `
|
||||
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #eee;">
|
||||
<h2>New Contact Form Submission</h2>
|
||||
<p><strong>From:</strong> Test User (test@example.com)</p>
|
||||
<p><strong>Submitted on:</strong> ${new Date().toLocaleString()}</p>
|
||||
<div style="background-color: #f9f9f9; padding: 15px; border-left: 3px solid #007bff; margin: 15px 0;">
|
||||
<p><strong>Message:</strong></p>
|
||||
<p>This is a test message simulating a contact form submission.</p>
|
||||
</div>
|
||||
<div style="font-size: 12px; color: #777; margin-top: 20px; padding-top: 10px; border-top: 1px solid #eee;">
|
||||
<p>This is an automated email from your website contact form.</p>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
await sendTestEmail(
|
||||
ADMIN_EMAIL,
|
||||
'New Contact Form Submission (Test)',
|
||||
'This is a test message simulating a contact form submission.',
|
||||
contactFormHtml
|
||||
);
|
||||
|
||||
console.log('\nAll tests completed successfully!');
|
||||
console.log('\nPlease check your inbox (and spam folder) for the test emails.');
|
||||
console.log('If you received some emails but not others, this can help identify the issue.');
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error running tests:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to send a test email
|
||||
async function sendTestEmail(to, subject, text, html, from = `"${WEBSITE_NAME}" <${ADMIN_EMAIL}>`) {
|
||||
try {
|
||||
const info = await transporter.sendMail({
|
||||
from,
|
||||
to,
|
||||
subject,
|
||||
text,
|
||||
html
|
||||
});
|
||||
|
||||
console.log(`Email sent successfully!`);
|
||||
console.log(`Message ID: ${info.messageId}`);
|
||||
console.log(`Response: ${info.response}`);
|
||||
return info;
|
||||
} catch (error) {
|
||||
console.error('Error sending email:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
101
email-test.cjs
101
email-test.cjs
@@ -1,101 +0,0 @@
|
||||
/**
|
||||
* ProtonMail SMTP Test Script
|
||||
*
|
||||
* This script tests the SMTP configuration for sending emails through ProtonMail.
|
||||
* Run with: node email-test.cjs
|
||||
*/
|
||||
|
||||
const nodemailer = require('nodemailer');
|
||||
require('dotenv').config();
|
||||
|
||||
// Get SMTP settings from environment variables
|
||||
const {
|
||||
SMTP_HOST = 'smtp.protonmail.ch',
|
||||
SMTP_PORT = '587',
|
||||
SMTP_USER,
|
||||
SMTP_PASS,
|
||||
ADMIN_EMAIL,
|
||||
WEBSITE_NAME = 'Website'
|
||||
} = process.env;
|
||||
|
||||
console.log('Email Configuration Test');
|
||||
console.log('----------------------');
|
||||
console.log(`SMTP Host: ${SMTP_HOST}`);
|
||||
console.log(`SMTP Port: ${SMTP_PORT}`);
|
||||
console.log(`SMTP User: ${SMTP_USER}`);
|
||||
console.log(`Admin Email: ${ADMIN_EMAIL}`);
|
||||
console.log(`Environment: ${process.env.NODE_ENV || 'development'}`);
|
||||
console.log('----------------------');
|
||||
|
||||
// Create a transporter with ProtonMail-specific settings
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: SMTP_HOST,
|
||||
port: parseInt(SMTP_PORT, 10),
|
||||
secure: parseInt(SMTP_PORT, 10) === 465, // true for 465, false for other ports
|
||||
auth: {
|
||||
user: SMTP_USER,
|
||||
pass: SMTP_PASS,
|
||||
},
|
||||
tls: {
|
||||
// Do not fail on invalid certs
|
||||
rejectUnauthorized: false,
|
||||
// Specific ciphers for ProtonMail
|
||||
ciphers: 'SSLv3'
|
||||
},
|
||||
debug: true // Enable debug output
|
||||
});
|
||||
|
||||
// Test the connection
|
||||
console.log('Testing SMTP connection...');
|
||||
transporter.verify((error, success) => {
|
||||
if (error) {
|
||||
console.error('SMTP Connection Error:', error);
|
||||
console.error('\nTroubleshooting Tips:');
|
||||
console.error('1. Check if your SMTP credentials are correct');
|
||||
console.error('2. For ProtonMail, ensure you\'re using an app-specific password');
|
||||
console.error('3. If using ProtonMail Bridge, make sure it\'s running');
|
||||
console.error('4. Verify your server allows outgoing connections on the SMTP port');
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log('SMTP Connection Successful!');
|
||||
|
||||
// Send a test email
|
||||
console.log('\nSending a test email...');
|
||||
const mailOptions = {
|
||||
from: `"${WEBSITE_NAME}" <${SMTP_USER}>`,
|
||||
to: ADMIN_EMAIL,
|
||||
subject: 'Email Configuration Test',
|
||||
text: 'This is a test email to verify your website\'s email configuration is working correctly.',
|
||||
html: `
|
||||
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #eee; border-radius: 5px;">
|
||||
<h2 style="color: #333;">Email Configuration Test</h2>
|
||||
<p>This is a test email to verify your website's email configuration is working correctly.</p>
|
||||
<p><strong>Configuration Details:</strong></p>
|
||||
<ul>
|
||||
<li>SMTP Host: ${SMTP_HOST}</li>
|
||||
<li>SMTP Port: ${SMTP_PORT}</li>
|
||||
<li>From: ${SMTP_USER}</li>
|
||||
<li>To: ${ADMIN_EMAIL}</li>
|
||||
<li>Time: ${new Date().toISOString()}</li>
|
||||
</ul>
|
||||
<p style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #eee; font-size: 12px; color: #666;">
|
||||
This is an automated test email. If you received this, your email configuration is working correctly.
|
||||
</p>
|
||||
</div>
|
||||
`
|
||||
};
|
||||
|
||||
transporter.sendMail(mailOptions, (error, info) => {
|
||||
if (error) {
|
||||
console.error('Error sending test email:', error);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log('Test email sent successfully!');
|
||||
console.log('Message ID:', info.messageId);
|
||||
console.log('Response:', info.response);
|
||||
console.log('\nIf you received the test email, your email configuration is working correctly.');
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
@@ -1,152 +0,0 @@
|
||||
/**
|
||||
* Production Email Test Script
|
||||
*
|
||||
* This script tests email delivery in production mode by sending test emails
|
||||
* with various configurations to help diagnose delivery issues.
|
||||
*
|
||||
* Run with: NODE_ENV=production node production-email-test.cjs
|
||||
*/
|
||||
|
||||
const nodemailer = require('nodemailer');
|
||||
require('dotenv').config();
|
||||
|
||||
// Environment variables
|
||||
const {
|
||||
SMTP_HOST = '',
|
||||
SMTP_PORT = '587',
|
||||
SMTP_USER = '',
|
||||
SMTP_PASS = '',
|
||||
ADMIN_EMAIL = '',
|
||||
WEBSITE_NAME = 'bergsma.it',
|
||||
NODE_ENV = 'production'
|
||||
} = process.env;
|
||||
|
||||
// Force production mode
|
||||
const isProduction = true;
|
||||
|
||||
console.log('Production Email Test');
|
||||
console.log('--------------------');
|
||||
console.log('Configuration:');
|
||||
console.log(`SMTP Host: ${SMTP_HOST}`);
|
||||
console.log(`SMTP Port: ${SMTP_PORT}`);
|
||||
console.log(`SMTP User: ${SMTP_USER}`);
|
||||
console.log(`Admin Email: ${ADMIN_EMAIL}`);
|
||||
console.log(`Website Name: ${WEBSITE_NAME}`);
|
||||
console.log(`Mode: ${isProduction ? 'production' : 'development'}`);
|
||||
console.log('--------------------');
|
||||
|
||||
// Create a transporter
|
||||
function createTransporter(options = {}) {
|
||||
const isProtonMail = SMTP_HOST.includes('protonmail');
|
||||
|
||||
return nodemailer.createTransport({
|
||||
host: SMTP_HOST,
|
||||
port: parseInt(SMTP_PORT, 10),
|
||||
secure: parseInt(SMTP_PORT, 10) === 465,
|
||||
auth: {
|
||||
user: SMTP_USER,
|
||||
pass: SMTP_PASS,
|
||||
},
|
||||
...(isProtonMail && {
|
||||
tls: {
|
||||
rejectUnauthorized: false,
|
||||
ciphers: 'SSLv3'
|
||||
}
|
||||
}),
|
||||
debug: true,
|
||||
...options
|
||||
});
|
||||
}
|
||||
|
||||
// Test different transporter configurations
|
||||
async function runTests() {
|
||||
try {
|
||||
// Test 1: Basic configuration
|
||||
console.log('\nTest 1: Basic configuration');
|
||||
const transporter1 = createTransporter();
|
||||
await testTransporter(transporter1, 'Basic configuration');
|
||||
|
||||
// Test 2: With secure=false explicitly set
|
||||
console.log('\nTest 2: With secure=false explicitly set');
|
||||
const transporter2 = createTransporter({ secure: false });
|
||||
await testTransporter(transporter2, 'secure=false configuration');
|
||||
|
||||
// Test 3: With requireTLS=true
|
||||
console.log('\nTest 3: With requireTLS=true');
|
||||
const transporter3 = createTransporter({ requireTLS: true });
|
||||
await testTransporter(transporter3, 'requireTLS=true configuration');
|
||||
|
||||
// Test 4: With different from address
|
||||
console.log('\nTest 4: With different from address');
|
||||
const transporter4 = createTransporter();
|
||||
await testTransporter(
|
||||
transporter4,
|
||||
'Different from address',
|
||||
{ from: `"Test" <${SMTP_USER}>` }
|
||||
);
|
||||
|
||||
console.log('\nAll tests completed!');
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error running tests:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Test a specific transporter configuration
|
||||
async function testTransporter(transporter, testName, options = {}) {
|
||||
console.log(`Testing ${testName}...`);
|
||||
|
||||
try {
|
||||
// Verify connection
|
||||
await new Promise((resolve, reject) => {
|
||||
transporter.verify((error, success) => {
|
||||
if (error) {
|
||||
console.error(`Connection test failed for ${testName}:`, error);
|
||||
reject(error);
|
||||
} else {
|
||||
console.log(`Connection successful for ${testName}`);
|
||||
resolve(success);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Send test email
|
||||
const fromAddress = options.from || `"${WEBSITE_NAME}" <${SMTP_USER}>`;
|
||||
|
||||
const info = await transporter.sendMail({
|
||||
from: fromAddress,
|
||||
to: ADMIN_EMAIL,
|
||||
subject: `Production Email Test: ${testName}`,
|
||||
text: `This is a test email from the production-email-test.cjs script using ${testName}.\n\nTime: ${new Date().toISOString()}`,
|
||||
html: `
|
||||
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #eee;">
|
||||
<h2>Production Email Test: ${testName}</h2>
|
||||
<p>This is a test email from the production-email-test.cjs script using ${testName}.</p>
|
||||
<p>Time: ${new Date().toISOString()}</p>
|
||||
<p>Configuration:</p>
|
||||
<ul>
|
||||
<li>SMTP Host: ${SMTP_HOST}</li>
|
||||
<li>SMTP Port: ${SMTP_PORT}</li>
|
||||
<li>From: ${fromAddress}</li>
|
||||
<li>To: ${ADMIN_EMAIL}</li>
|
||||
</ul>
|
||||
</div>
|
||||
`
|
||||
});
|
||||
|
||||
console.log(`Email sent successfully for ${testName}!`);
|
||||
console.log(`Message ID: ${info.messageId}`);
|
||||
console.log(`Response: ${info.response}`);
|
||||
|
||||
return info;
|
||||
} catch (error) {
|
||||
console.error(`Error in ${testName}:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Run the tests
|
||||
runTests().catch(error => {
|
||||
console.error('Unhandled error:', error);
|
||||
process.exit(1);
|
||||
});
|
@@ -1,69 +0,0 @@
|
||||
// Simple ProtonMail SMTP test
|
||||
const nodemailer = require('nodemailer');
|
||||
require('dotenv').config();
|
||||
|
||||
// Get SMTP settings from environment variables
|
||||
const {
|
||||
SMTP_HOST = 'smtp.protonmail.ch',
|
||||
SMTP_PORT = '587',
|
||||
SMTP_USER,
|
||||
SMTP_PASS,
|
||||
ADMIN_EMAIL
|
||||
} = process.env;
|
||||
|
||||
console.log('ProtonMail SMTP Test');
|
||||
console.log('-------------------');
|
||||
console.log(`SMTP Host: ${SMTP_HOST}`);
|
||||
console.log(`SMTP Port: ${SMTP_PORT}`);
|
||||
console.log(`SMTP User: ${SMTP_USER}`);
|
||||
console.log(`Admin Email: ${ADMIN_EMAIL}`);
|
||||
|
||||
// ProtonMail specific configuration
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: SMTP_HOST,
|
||||
port: parseInt(SMTP_PORT, 10),
|
||||
secure: false, // For ProtonMail, use false for port 587
|
||||
auth: {
|
||||
user: SMTP_USER,
|
||||
pass: SMTP_PASS,
|
||||
},
|
||||
tls: {
|
||||
// Do not fail on invalid certs
|
||||
rejectUnauthorized: false,
|
||||
// Specific ciphers for ProtonMail
|
||||
ciphers: 'SSLv3'
|
||||
},
|
||||
logger: true,
|
||||
debug: true // Include SMTP traffic in the logs
|
||||
});
|
||||
|
||||
// Verify connection
|
||||
console.log('\nTesting connection to ProtonMail SMTP server...');
|
||||
transporter.verify(function(error, _success) {
|
||||
if (error) {
|
||||
console.error('Connection failed:', error);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log('Server is ready to take our messages');
|
||||
|
||||
// Send test email
|
||||
console.log('\nSending test email...');
|
||||
transporter.sendMail({
|
||||
from: SMTP_USER,
|
||||
to: ADMIN_EMAIL,
|
||||
subject: 'ProtonMail SMTP Test',
|
||||
text: 'This is a test email from your website contact form.',
|
||||
html: '<p>This is a test email from your website contact form.</p>'
|
||||
}, (err, info) => {
|
||||
if (err) {
|
||||
console.error('Error sending email:', err);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log('Message sent successfully!');
|
||||
console.log('Message ID:', info.messageId);
|
||||
console.log('Response:', info.response);
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
@@ -1,97 +0,0 @@
|
||||
// ProtonMail SMTP test with alternative configuration
|
||||
const nodemailer = require('nodemailer');
|
||||
require('dotenv').config();
|
||||
|
||||
// Get SMTP settings from environment variables
|
||||
const {
|
||||
SMTP_USER,
|
||||
SMTP_PASS,
|
||||
ADMIN_EMAIL
|
||||
} = process.env;
|
||||
|
||||
console.log('ProtonMail SMTP Test (Alternative Configuration)');
|
||||
console.log('----------------------------------------------');
|
||||
console.log(`SMTP User: ${SMTP_USER}`);
|
||||
console.log(`Admin Email: ${ADMIN_EMAIL}`);
|
||||
|
||||
// Try alternative ProtonMail configuration
|
||||
// ProtonMail Bridge typically uses localhost:1025 or localhost:1143
|
||||
const transporterOptions = {
|
||||
host: 'mail.protonmail.ch',
|
||||
port: 443,
|
||||
secure: true,
|
||||
auth: {
|
||||
user: SMTP_USER,
|
||||
pass: SMTP_PASS,
|
||||
},
|
||||
tls: {
|
||||
rejectUnauthorized: false
|
||||
},
|
||||
logger: true,
|
||||
debug: true
|
||||
};
|
||||
|
||||
console.log('\nUsing configuration:');
|
||||
console.log(`Host: ${transporterOptions.host}`);
|
||||
console.log(`Port: ${transporterOptions.port}`);
|
||||
console.log(`Secure: ${transporterOptions.secure}`);
|
||||
|
||||
const transporter = nodemailer.createTransport(transporterOptions);
|
||||
|
||||
// Verify connection
|
||||
console.log('\nTesting connection to ProtonMail SMTP server...');
|
||||
transporter.verify(function(error, _success) {
|
||||
if (error) {
|
||||
console.error('Connection failed:', error);
|
||||
console.log('\nTrying alternative port (25)...');
|
||||
|
||||
// Try port 25
|
||||
const transporter2 = nodemailer.createTransport({
|
||||
...transporterOptions,
|
||||
port: 25,
|
||||
secure: false
|
||||
});
|
||||
|
||||
transporter2.verify(function(error2, _success2) {
|
||||
if (error2) {
|
||||
console.error('Connection with port 25 also failed:', error2);
|
||||
|
||||
console.log('\nImportant ProtonMail SMTP Notes:');
|
||||
console.log('1. ProtonMail requires the Bridge application for SMTP access from third-party apps');
|
||||
console.log('2. The Bridge runs locally and provides SMTP access via localhost:1025 or similar');
|
||||
console.log('3. You may need to install and configure ProtonMail Bridge on your server');
|
||||
console.log('4. Or use ProtonMail\'s API instead of SMTP for sending emails');
|
||||
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log('Connection successful with port 25!');
|
||||
sendTestEmail(transporter2);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log('Server is ready to take our messages');
|
||||
sendTestEmail(transporter);
|
||||
}
|
||||
});
|
||||
|
||||
function sendTestEmail(transport) {
|
||||
// Send test email
|
||||
console.log('\nSending test email...');
|
||||
transport.sendMail({
|
||||
from: SMTP_USER,
|
||||
to: ADMIN_EMAIL,
|
||||
subject: 'ProtonMail SMTP Test (Alternative Config)',
|
||||
text: 'This is a test email from your website contact form.',
|
||||
html: '<p>This is a test email from your website contact form.</p>'
|
||||
}, (err, info) => {
|
||||
if (err) {
|
||||
console.error('Error sending email:', err);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log('Message sent successfully!');
|
||||
console.log('Message ID:', info.messageId);
|
||||
console.log('Response:', info.response);
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
@@ -1,252 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Contact Form Test</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
.form-group {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
font-weight: bold;
|
||||
}
|
||||
input, textarea {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
}
|
||||
button {
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
padding: 10px 15px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.success {
|
||||
background-color: #d4edda;
|
||||
color: #155724;
|
||||
padding: 15px;
|
||||
margin-bottom: 20px;
|
||||
border-radius: 4px;
|
||||
display: none;
|
||||
}
|
||||
.error {
|
||||
background-color: #f8d7da;
|
||||
color: #721c24;
|
||||
padding: 15px;
|
||||
margin-bottom: 20px;
|
||||
border-radius: 4px;
|
||||
display: none;
|
||||
}
|
||||
.debug {
|
||||
background-color: #f8f9fa;
|
||||
border: 1px solid #ddd;
|
||||
padding: 15px;
|
||||
margin-top: 20px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
#debug-log {
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
white-space: pre-wrap;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Contact Form Test</h1>
|
||||
|
||||
<div id="success-message" class="success">
|
||||
Your message has been sent successfully!
|
||||
</div>
|
||||
|
||||
<div id="error-message" class="error">
|
||||
There was an error sending your message. Please try again.
|
||||
</div>
|
||||
|
||||
<form id="contact-form">
|
||||
<input type="hidden" name="csrf_token" id="csrf_token" value="">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name">Name:</label>
|
||||
<input type="text" id="name" name="name" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Email:</label>
|
||||
<input type="email" id="email" name="email" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="message">Message:</label>
|
||||
<textarea id="message" name="message" rows="5" required></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>
|
||||
<input type="checkbox" id="disclaimer" name="disclaimer" required>
|
||||
I agree to the terms and conditions
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button type="submit">Send Message</button>
|
||||
</form>
|
||||
|
||||
<div class="debug">
|
||||
<h3>Debug Log</h3>
|
||||
<div id="debug-log"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Debug logging function
|
||||
function log(message) {
|
||||
const debugLog = document.getElementById('debug-log');
|
||||
const timestamp = new Date().toISOString();
|
||||
debugLog.innerHTML += `[${timestamp}] ${message}\n`;
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// Fetch CSRF token
|
||||
async function fetchCsrfToken() {
|
||||
log('Fetching CSRF token...');
|
||||
try {
|
||||
const response = await fetch('/api/contact?csrf=true');
|
||||
log(`CSRF response status: ${response.status}`);
|
||||
|
||||
if (!response.ok) {
|
||||
log(`CSRF request failed: ${response.statusText}`);
|
||||
return '';
|
||||
}
|
||||
|
||||
const text = await response.text();
|
||||
log(`CSRF response text: ${text}`);
|
||||
|
||||
try {
|
||||
const data = JSON.parse(text);
|
||||
log(`CSRF token received: ${data.csrfToken ? 'yes' : 'no'}`);
|
||||
return data.csrfToken;
|
||||
} catch (parseError) {
|
||||
log(`Error parsing CSRF response: ${parseError.message}`);
|
||||
return '';
|
||||
}
|
||||
} catch (error) {
|
||||
log(`Error fetching CSRF token: ${error.message}`);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize form
|
||||
async function initForm() {
|
||||
log('Initializing form...');
|
||||
const csrfToken = await fetchCsrfToken();
|
||||
|
||||
if (csrfToken) {
|
||||
document.getElementById('csrf_token').value = csrfToken;
|
||||
log('CSRF token set in form');
|
||||
} else {
|
||||
log('Failed to get CSRF token');
|
||||
}
|
||||
|
||||
// Set default values for testing
|
||||
document.getElementById('name').value = 'Test User';
|
||||
document.getElementById('email').value = 'richard@bergsma.it';
|
||||
document.getElementById('message').value = 'This is a test message from the test-contact-form.html page. ' + new Date().toISOString();
|
||||
|
||||
log('Form initialized with test values');
|
||||
}
|
||||
|
||||
// Handle form submission
|
||||
async function handleSubmit(event) {
|
||||
event.preventDefault();
|
||||
log('Form submitted');
|
||||
|
||||
// Reset messages
|
||||
document.getElementById('success-message').style.display = 'none';
|
||||
document.getElementById('error-message').style.display = 'none';
|
||||
|
||||
// Get form data
|
||||
const form = document.getElementById('contact-form');
|
||||
const formData = new FormData(form);
|
||||
|
||||
// Log form data
|
||||
log('Form data:');
|
||||
for (const [key, value] of formData.entries()) {
|
||||
log(`${key}: ${value}`);
|
||||
}
|
||||
|
||||
// Add timestamp
|
||||
formData.append('timestamp', Date.now().toString());
|
||||
|
||||
try {
|
||||
log('Sending form data to /api/contact');
|
||||
const response = await fetch('/api/contact', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
log(`Response status: ${response.status}`);
|
||||
const text = await response.text();
|
||||
log(`Response text: ${text}`);
|
||||
|
||||
try {
|
||||
const result = JSON.parse(text);
|
||||
log(`Response parsed: ${JSON.stringify(result)}`);
|
||||
|
||||
if (result.success) {
|
||||
log('Form submission successful');
|
||||
document.getElementById('success-message').style.display = 'block';
|
||||
form.reset();
|
||||
|
||||
// Get a new CSRF token
|
||||
const newToken = await fetchCsrfToken();
|
||||
if (newToken) {
|
||||
document.getElementById('csrf_token').value = newToken;
|
||||
}
|
||||
} else {
|
||||
log(`Form submission failed: ${JSON.stringify(result.errors || {})}`);
|
||||
document.getElementById('error-message').style.display = 'block';
|
||||
|
||||
if (result.errors && result.errors.csrf) {
|
||||
log('CSRF token invalid, getting new token');
|
||||
const newToken = await fetchCsrfToken();
|
||||
if (newToken) {
|
||||
document.getElementById('csrf_token').value = newToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (parseError) {
|
||||
log(`Error parsing response: ${parseError.message}`);
|
||||
document.getElementById('error-message').style.display = 'block';
|
||||
}
|
||||
} catch (error) {
|
||||
log(`Error submitting form: ${error.message}`);
|
||||
document.getElementById('error-message').style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize when DOM is loaded
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
log('DOM loaded');
|
||||
initForm();
|
||||
|
||||
// Add form submit handler
|
||||
document.getElementById('contact-form').addEventListener('submit', handleSubmit);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@@ -1,183 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Language Persistence Test</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
h1 {
|
||||
color: #333;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.test-section {
|
||||
margin-bottom: 30px;
|
||||
padding: 15px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
.test-buttons {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
button {
|
||||
padding: 8px 16px;
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:hover {
|
||||
background-color: #45a049;
|
||||
}
|
||||
.language-status {
|
||||
margin-top: 15px;
|
||||
padding: 10px;
|
||||
background-color: #e9f7ef;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.navigation-links {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.navigation-links a {
|
||||
display: inline-block;
|
||||
margin-right: 15px;
|
||||
padding: 8px 16px;
|
||||
background-color: #2196F3;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.navigation-links a:hover {
|
||||
background-color: #0b7dda;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Language Persistence Test</h1>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Current Language Status</h2>
|
||||
<div class="language-status">
|
||||
<p><strong>URL Language:</strong> <span id="url-language">Checking...</span></p>
|
||||
<p><strong>LocalStorage Language:</strong> <span id="localstorage-language">Checking...</span></p>
|
||||
<p><strong>Cookie Language:</strong> <span id="cookie-language">Checking...</span></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Test Language Selection</h2>
|
||||
<p>Click on a language to test the language persistence:</p>
|
||||
<div class="test-buttons">
|
||||
<button onclick="changeLanguage('en')">English</button>
|
||||
<button onclick="changeLanguage('nl')">Dutch</button>
|
||||
<button onclick="changeLanguage('de')">German</button>
|
||||
<button onclick="changeLanguage('fr')">French</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Navigation Test</h2>
|
||||
<p>Use these links to test language persistence during navigation:</p>
|
||||
<div class="navigation-links">
|
||||
<a href="/" id="home-link">Home</a>
|
||||
<a href="/aboutme" id="aboutme-link">About Me</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Function to get language from URL
|
||||
function getLanguageFromURL() {
|
||||
const pathSegments = window.location.pathname.split('/').filter(Boolean);
|
||||
const supportedLanguages = ['en', 'nl', 'de', 'fr'];
|
||||
if (pathSegments.length > 0 && supportedLanguages.includes(pathSegments[0])) {
|
||||
return pathSegments[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Function to get language from localStorage
|
||||
function getStoredLanguage() {
|
||||
return localStorage.getItem('preferredLanguage');
|
||||
}
|
||||
|
||||
// Function to get language from cookie
|
||||
function getLanguageFromCookie() {
|
||||
const cookies = document.cookie.split(';');
|
||||
for (let i = 0; i < cookies.length; i++) {
|
||||
const cookie = cookies[i].trim();
|
||||
if (cookie.startsWith('preferredLanguage=')) {
|
||||
return cookie.substring('preferredLanguage='.length);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Function to update the language status display
|
||||
function updateLanguageStatus() {
|
||||
document.getElementById('url-language').textContent = getLanguageFromURL() || 'Not set';
|
||||
document.getElementById('localstorage-language').textContent = getStoredLanguage() || 'Not set';
|
||||
document.getElementById('cookie-language').textContent = getLanguageFromCookie() || 'Not set';
|
||||
}
|
||||
|
||||
// Function to change language
|
||||
function changeLanguage(langCode) {
|
||||
// Store language in localStorage
|
||||
localStorage.setItem('preferredLanguage', langCode);
|
||||
|
||||
// Store language in cookie
|
||||
const expirationDate = new Date();
|
||||
expirationDate.setFullYear(expirationDate.getFullYear() + 1);
|
||||
document.cookie = `preferredLanguage=${langCode}; expires=${expirationDate.toUTCString()}; path=/; SameSite=Lax`;
|
||||
|
||||
// Update the language status display
|
||||
updateLanguageStatus();
|
||||
|
||||
// Update navigation links with the selected language
|
||||
updateNavigationLinks(langCode);
|
||||
|
||||
// Dispatch a custom event for language change
|
||||
const event = new CustomEvent('languageChanged', {
|
||||
detail: {
|
||||
langCode,
|
||||
previousLangCode: getLanguageFromURL() || 'en',
|
||||
willReload: false
|
||||
}
|
||||
});
|
||||
document.dispatchEvent(event);
|
||||
|
||||
// Show a success message
|
||||
alert(`Language changed to ${langCode}. Navigation links have been updated.`);
|
||||
}
|
||||
|
||||
// Function to update navigation links with the selected language
|
||||
function updateNavigationLinks(langCode) {
|
||||
const homeLink = document.getElementById('home-link');
|
||||
const aboutmeLink = document.getElementById('aboutme-link');
|
||||
|
||||
homeLink.href = `/${langCode}/`;
|
||||
aboutmeLink.href = `/${langCode}/aboutme`;
|
||||
}
|
||||
|
||||
// Initialize the page
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Update the language status display
|
||||
updateLanguageStatus();
|
||||
|
||||
// Update navigation links with the current language
|
||||
const currentLang = getStoredLanguage() || getLanguageFromCookie() || 'en';
|
||||
updateNavigationLinks(currentLang);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@@ -1,177 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Language Switching Test</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
h1 {
|
||||
color: #333;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.test-section {
|
||||
margin-bottom: 30px;
|
||||
padding: 15px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
.test-button {
|
||||
display: inline-block;
|
||||
margin: 5px;
|
||||
padding: 8px 15px;
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
}
|
||||
.test-button:hover {
|
||||
background-color: #45a049;
|
||||
}
|
||||
.language-button {
|
||||
display: inline-block;
|
||||
margin: 5px;
|
||||
padding: 8px 15px;
|
||||
background-color: #2196F3;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
}
|
||||
.language-button:hover {
|
||||
background-color: #0b7dda;
|
||||
}
|
||||
.result {
|
||||
margin-top: 10px;
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
background-color: #fff;
|
||||
}
|
||||
code {
|
||||
background-color: #f1f1f1;
|
||||
padding: 2px 4px;
|
||||
border-radius: 3px;
|
||||
font-family: monospace;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Language Switching Test</h1>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Current URL Information</h2>
|
||||
<div class="result" id="url-info">Loading...</div>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Switch Language</h2>
|
||||
<p>Click on a language to switch:</p>
|
||||
<div>
|
||||
<a href="#" class="language-button" data-lang="en">English</a>
|
||||
<a href="#" class="language-button" data-lang="nl">Dutch</a>
|
||||
<a href="#" class="language-button" data-lang="de">German</a>
|
||||
<a href="#" class="language-button" data-lang="fr">French</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Test Hash Navigation</h2>
|
||||
<p>Click on a section to navigate:</p>
|
||||
<div>
|
||||
<a href="#services" class="test-button">Services</a>
|
||||
<a href="#contact" class="test-button">Contact</a>
|
||||
<a href="#about" class="test-button">About</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Test Page Navigation</h2>
|
||||
<p>Navigate to different pages:</p>
|
||||
<div>
|
||||
<a href="/" class="test-button">Home</a>
|
||||
<a href="/aboutme" class="test-button">About Me</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Display current URL information
|
||||
function updateUrlInfo() {
|
||||
const url = new URL(window.location.href);
|
||||
const pathSegments = url.pathname.split('/').filter(Boolean);
|
||||
const currentLang = pathSegments[0] || 'none';
|
||||
|
||||
const infoDiv = document.getElementById('url-info');
|
||||
infoDiv.innerHTML = `
|
||||
<p><strong>Full URL:</strong> ${url.href}</p>
|
||||
<p><strong>Path:</strong> ${url.pathname}</p>
|
||||
<p><strong>Hash:</strong> ${url.hash || 'none'}</p>
|
||||
<p><strong>Current Language:</strong> ${currentLang}</p>
|
||||
<p><strong>Path Segments:</strong> ${JSON.stringify(pathSegments)}</p>
|
||||
`;
|
||||
}
|
||||
|
||||
// Initialize
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
updateUrlInfo();
|
||||
|
||||
// Set up language buttons
|
||||
document.querySelectorAll('.language-button').forEach(button => {
|
||||
button.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
const lang = button.getAttribute('data-lang');
|
||||
if (!lang) return;
|
||||
|
||||
// Get current URL information
|
||||
const currentUrl = new URL(window.location.href);
|
||||
const currentPath = currentUrl.pathname.replace(/\/$/, '');
|
||||
const currentHash = currentUrl.hash;
|
||||
const pathSegments = currentPath.split('/').filter(Boolean);
|
||||
|
||||
// Check if we're on a language-specific path
|
||||
const supportedLanguages = ['en', 'nl', 'de', 'fr'];
|
||||
const isLangPath = supportedLanguages.includes(pathSegments[0]);
|
||||
|
||||
// Extract the page path without language
|
||||
let pagePath = '';
|
||||
if (isLangPath && pathSegments.length > 1) {
|
||||
// If we're on a language-specific path, get everything after the language code
|
||||
pagePath = `/${pathSegments.slice(1).join('/')}`;
|
||||
} else if (!isLangPath && pathSegments.length > 0) {
|
||||
// If we're not on a language-specific path, use the current path
|
||||
pagePath = `/${pathSegments.join('/')}`;
|
||||
}
|
||||
|
||||
// Handle special case for root path
|
||||
const isRootPath = pathSegments.length === 0 || (isLangPath && pathSegments.length === 1);
|
||||
|
||||
// Construct the new URL
|
||||
let newUrl = isRootPath ? `/${lang}` : `/${lang}${pagePath}`;
|
||||
|
||||
// Append hash fragment if it exists
|
||||
if (currentHash) {
|
||||
newUrl += currentHash;
|
||||
}
|
||||
|
||||
// Navigate to the new URL
|
||||
window.location.href = newUrl;
|
||||
});
|
||||
});
|
||||
|
||||
// Update URL info when hash changes
|
||||
window.addEventListener('hashchange', updateUrlInfo);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@@ -1,31 +0,0 @@
|
||||
import { testEmailConfiguration, sendAdminNotification } from '../utils/email-handler';
|
||||
import 'dotenv/config';
|
||||
|
||||
async function runEmailTest() {
|
||||
console.log('Starting email configuration test...');
|
||||
|
||||
// Test the SMTP connection
|
||||
const configTest = await testEmailConfiguration();
|
||||
console.log(`Configuration test result: ${configTest ? 'SUCCESS' : 'FAILED'}`);
|
||||
|
||||
if (configTest) {
|
||||
// Try sending a test email
|
||||
console.log('Attempting to send a test email...');
|
||||
const emailResult = await sendAdminNotification(
|
||||
'Test User',
|
||||
'test@example.com',
|
||||
'This is a test message sent at ' + new Date().toISOString(),
|
||||
'127.0.0.1',
|
||||
'Email Test Script'
|
||||
);
|
||||
|
||||
console.log(`Test email result: ${emailResult ? 'SENT' : 'FAILED'}`);
|
||||
}
|
||||
|
||||
console.log('Email test completed');
|
||||
}
|
||||
|
||||
runEmailTest().catch((error) => {
|
||||
console.error('Error running email test:', error);
|
||||
process.exit(1);
|
||||
});
|
@@ -1,51 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Test script for the contact form API using curl
|
||||
# This script simulates a form submission to the contact form API
|
||||
|
||||
API_URL="http://localhost:4321/api/contact"
|
||||
# Get admin email from environment variable or use a placeholder for testing
|
||||
ADMIN_EMAIL="${ADMIN_EMAIL:-admin@example.com}"
|
||||
|
||||
echo "Starting contact form test with curl..."
|
||||
echo "API URL: $API_URL"
|
||||
|
||||
# Step 1: Get CSRF token
|
||||
echo "Getting CSRF token..."
|
||||
CSRF_RESPONSE=$(curl -s "$API_URL?csrf=true")
|
||||
echo "CSRF Response: $CSRF_RESPONSE"
|
||||
|
||||
# Extract CSRF token
|
||||
CSRF_TOKEN=$(echo $CSRF_RESPONSE | grep -o '"csrfToken":"[^"]*"' | cut -d'"' -f4)
|
||||
echo "CSRF Token: $CSRF_TOKEN"
|
||||
|
||||
if [ -z "$CSRF_TOKEN" ]; then
|
||||
echo "Failed to get CSRF token. Aborting test."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Step 2: Submit the form
|
||||
echo "Submitting form..."
|
||||
FORM_RESPONSE=$(curl -s -X POST "$API_URL" \
|
||||
-H "Content-Type: application/x-www-form-urlencoded" \
|
||||
-H "Accept: application/json" \
|
||||
-H "User-Agent: test-contact-curl-script" \
|
||||
--data-urlencode "name=Test User" \
|
||||
--data-urlencode "email=$ADMIN_EMAIL" \
|
||||
--data-urlencode "message=This is a test message from the test-contact-curl.sh script. $(date)" \
|
||||
--data-urlencode "disclaimer=on" \
|
||||
--data-urlencode "csrf_token=$CSRF_TOKEN" \
|
||||
--data-urlencode "timestamp=$(date +%s)")
|
||||
|
||||
echo "Form submission response: $FORM_RESPONSE"
|
||||
|
||||
# Check if submission was successful
|
||||
if echo "$FORM_RESPONSE" | grep -q '"success":true'; then
|
||||
echo "Form submission successful!"
|
||||
else
|
||||
echo "Form submission failed."
|
||||
echo "Response: $FORM_RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Test completed successfully."
|
@@ -1,133 +0,0 @@
|
||||
/**
|
||||
* Test script for the contact form API
|
||||
* This script simulates a form submission to the contact form API
|
||||
*/
|
||||
|
||||
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
||||
const FormData = require('form-data');
|
||||
require('dotenv').config();
|
||||
|
||||
// URL of the contact form API
|
||||
const API_URL = 'http://localhost:4321/api/contact';
|
||||
|
||||
// Function to get a CSRF token
|
||||
async function getCsrfToken() {
|
||||
try {
|
||||
console.log(`Fetching CSRF token from ${API_URL}?csrf=true`);
|
||||
const response = await fetch(`${API_URL}?csrf=true`);
|
||||
console.log('CSRF response status:', response.status);
|
||||
|
||||
if (!response.ok) {
|
||||
console.error('CSRF request failed:', response.statusText);
|
||||
return null;
|
||||
}
|
||||
|
||||
const text = await response.text();
|
||||
console.log('CSRF response text:', text);
|
||||
|
||||
try {
|
||||
const data = JSON.parse(text);
|
||||
console.log('CSRF token data:', data);
|
||||
return data.csrfToken;
|
||||
} catch (parseError) {
|
||||
console.error('Error parsing CSRF response:', parseError);
|
||||
console.error('Response was not valid JSON:', text);
|
||||
return null;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error getting CSRF token:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Function to submit the form
|
||||
async function submitForm(csrfToken) {
|
||||
console.log('Creating form data for submission');
|
||||
|
||||
// Create form data
|
||||
const formData = new FormData();
|
||||
const testEmail = process.env.ADMIN_EMAIL || 'richard@bergsma.it';
|
||||
const testMessage = 'This is a test message from the test-contact-form.cjs script. ' + new Date().toISOString();
|
||||
|
||||
formData.append('name', 'Test User');
|
||||
formData.append('email', testEmail);
|
||||
formData.append('message', testMessage);
|
||||
formData.append('disclaimer', 'on');
|
||||
formData.append('csrf_token', csrfToken);
|
||||
formData.append('timestamp', Date.now().toString());
|
||||
|
||||
console.log('Submitting form with data:', {
|
||||
name: 'Test User',
|
||||
email: testEmail,
|
||||
messageLength: testMessage.length,
|
||||
disclaimer: 'on',
|
||||
csrfToken: csrfToken ? 'present' : 'missing',
|
||||
});
|
||||
|
||||
try {
|
||||
console.log(`Sending POST request to ${API_URL}`);
|
||||
const response = await fetch(API_URL, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'User-Agent': 'test-contact-form-script'
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Response status:', response.status);
|
||||
|
||||
if (!response.ok) {
|
||||
console.error('Form submission failed with status:', response.status, response.statusText);
|
||||
}
|
||||
|
||||
const text = await response.text();
|
||||
console.log('Response text:', text);
|
||||
|
||||
try {
|
||||
const result = JSON.parse(text);
|
||||
console.log('Form submission result:', result);
|
||||
return result;
|
||||
} catch (parseError) {
|
||||
console.error('Error parsing response:', parseError);
|
||||
console.error('Response was not valid JSON:', text);
|
||||
return { success: false, error: 'Invalid JSON response' };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error submitting form:', error);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
|
||||
// Main function
|
||||
async function main() {
|
||||
console.log('Starting contact form test...');
|
||||
console.log(`API URL: ${API_URL}`);
|
||||
|
||||
// Get CSRF token
|
||||
console.log('Getting CSRF token...');
|
||||
const csrfToken = await getCsrfToken();
|
||||
|
||||
if (!csrfToken) {
|
||||
console.error('Failed to get CSRF token. Aborting test.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('CSRF token received:', csrfToken ? 'Yes' : 'No');
|
||||
|
||||
// Submit the form
|
||||
console.log('Submitting form...');
|
||||
const result = await submitForm(csrfToken);
|
||||
|
||||
if (result.success) {
|
||||
console.log('Form submission successful!');
|
||||
} else {
|
||||
console.error('Form submission failed:', result);
|
||||
}
|
||||
}
|
||||
|
||||
// Run the test
|
||||
main().catch(error => {
|
||||
console.error('Unhandled error:', error);
|
||||
process.exit(1);
|
||||
});
|
@@ -1,31 +0,0 @@
|
||||
import { testEmailConfiguration, sendAdminNotification } from './src/utils/email-handler.js';
|
||||
import 'dotenv/config';
|
||||
|
||||
async function runEmailTest() {
|
||||
console.log('Starting email configuration test...');
|
||||
|
||||
// Test the SMTP connection
|
||||
const configTest = await testEmailConfiguration();
|
||||
console.log(`Configuration test result: ${configTest ? 'SUCCESS' : 'FAILED'}`);
|
||||
|
||||
if (configTest) {
|
||||
// Try sending a test email
|
||||
console.log('Attempting to send a test email...');
|
||||
const emailResult = await sendAdminNotification(
|
||||
'Test User',
|
||||
'test@example.com',
|
||||
'This is a test message sent at ' + new Date().toISOString(),
|
||||
'127.0.0.1',
|
||||
'Email Test Script'
|
||||
);
|
||||
|
||||
console.log(`Test email result: ${emailResult ? 'SENT' : 'FAILED'}`);
|
||||
}
|
||||
|
||||
console.log('Email test completed');
|
||||
}
|
||||
|
||||
runEmailTest().catch(error => {
|
||||
console.error('Error running email test:', error);
|
||||
process.exit(1);
|
||||
});
|
87
test-smtp.js
87
test-smtp.js
@@ -1,87 +0,0 @@
|
||||
const nodemailer = require('nodemailer');
|
||||
require('dotenv').config();
|
||||
|
||||
// Get SMTP settings from environment variables
|
||||
const {
|
||||
SMTP_HOST,
|
||||
SMTP_PORT,
|
||||
SMTP_USER,
|
||||
SMTP_PASS,
|
||||
ADMIN_EMAIL,
|
||||
WEBSITE_NAME
|
||||
} = process.env;
|
||||
|
||||
console.log('SMTP Configuration Test');
|
||||
console.log('----------------------');
|
||||
console.log(`SMTP Host: ${SMTP_HOST}`);
|
||||
console.log(`SMTP Port: ${SMTP_PORT}`);
|
||||
console.log(`SMTP User: ${SMTP_USER}`);
|
||||
console.log(`Admin Email: ${ADMIN_EMAIL}`);
|
||||
console.log(`Website Name: ${WEBSITE_NAME}`);
|
||||
console.log('----------------------');
|
||||
|
||||
// Create a transporter
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: SMTP_HOST,
|
||||
port: parseInt(SMTP_PORT, 10),
|
||||
secure: parseInt(SMTP_PORT, 10) === 465,
|
||||
auth: {
|
||||
user: SMTP_USER,
|
||||
pass: SMTP_PASS,
|
||||
},
|
||||
// Required for ProtonMail
|
||||
tls: {
|
||||
ciphers: 'SSLv3',
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
});
|
||||
|
||||
// Test the connection
|
||||
console.log('Testing SMTP connection...');
|
||||
transporter.verify((error, success) => {
|
||||
if (error) {
|
||||
console.error('SMTP Connection Error:', error);
|
||||
console.error('Error Name:', error.name);
|
||||
console.error('Error Message:', error.message);
|
||||
|
||||
// Provide troubleshooting advice based on error
|
||||
if (error.message.includes('ECONNREFUSED')) {
|
||||
console.error('\nTroubleshooting: Connection refused');
|
||||
console.error('- Check if the SMTP server address is correct');
|
||||
console.error('- Verify the port is correct and not blocked by a firewall');
|
||||
console.error('- Ensure your internet connection is working');
|
||||
} else if (error.message.includes('Invalid login') || error.message.includes('authentication failed')) {
|
||||
console.error('\nTroubleshooting: Authentication failed');
|
||||
console.error('- Verify your username and password are correct');
|
||||
console.error('- For ProtonMail, ensure you\'re using an app-specific password');
|
||||
console.error('- Check if 2FA is enabled and properly configured');
|
||||
} else if (error.message.includes('certificate')) {
|
||||
console.error('\nTroubleshooting: SSL/TLS Certificate Error');
|
||||
console.error('- The server\'s SSL certificate could not be verified');
|
||||
console.error('- This might be resolved by setting rejectUnauthorized: false (already set)');
|
||||
}
|
||||
} else {
|
||||
console.log('SMTP Connection Successful!');
|
||||
console.log('The server is ready to accept messages');
|
||||
|
||||
// Send a test email
|
||||
console.log('\nSending a test email...');
|
||||
const mailOptions = {
|
||||
from: `"${WEBSITE_NAME}" <${ADMIN_EMAIL}>`,
|
||||
to: ADMIN_EMAIL,
|
||||
subject: 'SMTP Test Email',
|
||||
text: 'This is a test email to verify SMTP configuration is working correctly.',
|
||||
html: '<p>This is a test email to verify SMTP configuration is working correctly.</p>'
|
||||
};
|
||||
|
||||
transporter.sendMail(mailOptions, (error, info) => {
|
||||
if (error) {
|
||||
console.error('Error sending test email:', error);
|
||||
} else {
|
||||
console.log('Test email sent successfully!');
|
||||
console.log('Message ID:', info.messageId);
|
||||
console.log('Response:', info.response);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user