Initial commit: Mail service with Brevo SMTP
- Express server with REST API for sending emails - SQLite database for persistent email history - Web interface with form (recipient, CC, subject, text/HTML) - Email footer with embedded image (CID attachment) - Nodemailer configured for Brevo SMTP relay Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
65
public/index.html
Normal file
65
public/index.html
Normal file
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Mail-Service</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="panel form-panel">
|
||||
<h2>Mail Versenden</h2>
|
||||
<form id="mailForm">
|
||||
<div class="form-group">
|
||||
<label for="to">Empfänger *</label>
|
||||
<input type="email" id="to" name="to" required placeholder="empfaenger@example.com">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="cc">CC</label>
|
||||
<input type="email" id="cc" name="cc" placeholder="cc@example.com">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="subject">Betreff *</label>
|
||||
<input type="text" id="subject" name="subject" required placeholder="Betreff der E-Mail">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Format</label>
|
||||
<div class="radio-group">
|
||||
<label>
|
||||
<input type="radio" name="format" value="text" checked> Text
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" name="format" value="html"> HTML
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="body">Nachricht *</label>
|
||||
<textarea id="body" name="body" required rows="8" placeholder="Ihre Nachricht..."></textarea>
|
||||
</div>
|
||||
|
||||
<button type="submit" id="submitBtn">Senden</button>
|
||||
</form>
|
||||
|
||||
<div id="status" class="status hidden"></div>
|
||||
</div>
|
||||
|
||||
<div class="panel history-panel">
|
||||
<div class="history-header">
|
||||
<h2>Versand-Historie</h2>
|
||||
<button id="clearHistory" class="btn-secondary">Leeren</button>
|
||||
</div>
|
||||
<div id="historyList" class="history-list">
|
||||
<p class="empty-message">Keine E-Mails gesendet</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
149
public/script.js
Normal file
149
public/script.js
Normal file
@@ -0,0 +1,149 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const form = document.getElementById('mailForm');
|
||||
const status = document.getElementById('status');
|
||||
const submitBtn = document.getElementById('submitBtn');
|
||||
const historyList = document.getElementById('historyList');
|
||||
const clearHistoryBtn = document.getElementById('clearHistory');
|
||||
|
||||
// Load history on page load
|
||||
loadHistory();
|
||||
|
||||
// Form submission
|
||||
form.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const formData = new FormData(form);
|
||||
const data = {
|
||||
to: formData.get('to'),
|
||||
cc: formData.get('cc') || undefined,
|
||||
subject: formData.get('subject'),
|
||||
body: formData.get('body'),
|
||||
isHtml: formData.get('format') === 'html'
|
||||
};
|
||||
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.textContent = 'Sende...';
|
||||
hideStatus();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/send', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showStatus('E-Mail erfolgreich gesendet!', 'success');
|
||||
form.reset();
|
||||
} else {
|
||||
showStatus(result.error, 'error');
|
||||
}
|
||||
|
||||
loadHistory();
|
||||
} catch (error) {
|
||||
showStatus('Netzwerkfehler: ' + error.message, 'error');
|
||||
} finally {
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.textContent = 'Senden';
|
||||
}
|
||||
});
|
||||
|
||||
// Clear history
|
||||
clearHistoryBtn.addEventListener('click', async () => {
|
||||
if (!confirm('Gesamte Historie löschen?')) return;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/history', { method: 'DELETE' });
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
loadHistory();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error clearing history:', error);
|
||||
}
|
||||
});
|
||||
|
||||
// Load history from server
|
||||
async function loadHistory() {
|
||||
try {
|
||||
const response = await fetch('/api/history');
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
renderHistory(result.history);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading history:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Render history list
|
||||
function renderHistory(history) {
|
||||
if (!history || history.length === 0) {
|
||||
historyList.innerHTML = '<p class="empty-message">Keine E-Mails gesendet</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
historyList.innerHTML = history.map(item => `
|
||||
<div class="history-item ${item.status}">
|
||||
<div class="history-item-header">
|
||||
<span class="history-item-status">
|
||||
${item.status === 'success' ? '✓ Erfolgreich' : '✗ Fehlgeschlagen'}
|
||||
</span>
|
||||
<button class="delete-btn" onclick="deleteHistoryItem(${item.id})" title="Löschen">✕</button>
|
||||
</div>
|
||||
<div class="history-item-date">${formatDate(item.created_at)}</div>
|
||||
<div class="history-item-to">An: ${escapeHtml(item.to_email)}${item.cc_email ? `, CC: ${escapeHtml(item.cc_email)}` : ''}</div>
|
||||
<div class="history-item-subject">Betreff: ${escapeHtml(item.subject)}</div>
|
||||
${item.error_message ? `<div class="history-item-error">Fehler: ${escapeHtml(item.error_message)}</div>` : ''}
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
// Delete single history item
|
||||
window.deleteHistoryItem = async (id) => {
|
||||
try {
|
||||
const response = await fetch(`/api/history/${id}`, { method: 'DELETE' });
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
loadHistory();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error deleting item:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// Show status message
|
||||
function showStatus(message, type) {
|
||||
status.textContent = message;
|
||||
status.className = `status ${type}`;
|
||||
}
|
||||
|
||||
// Hide status message
|
||||
function hideStatus() {
|
||||
status.className = 'status hidden';
|
||||
}
|
||||
|
||||
// Format date
|
||||
function formatDate(dateStr) {
|
||||
const date = new Date(dateStr + 'Z');
|
||||
return date.toLocaleString('de-DE', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
}
|
||||
|
||||
// Escape HTML to prevent XSS
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
});
|
||||
257
public/style.css
Normal file
257
public/style.css
Normal file
@@ -0,0 +1,257 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
|
||||
background: #f5f5f5;
|
||||
color: #333;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
padding: 20px;
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.panel {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.form-panel {
|
||||
flex: 1;
|
||||
max-width: 600px;
|
||||
}
|
||||
|
||||
.history-panel {
|
||||
flex: 1;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin-bottom: 20px;
|
||||
color: #2c3e50;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
font-weight: 500;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
input[type="text"],
|
||||
input[type="email"],
|
||||
textarea {
|
||||
width: 100%;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
input:focus,
|
||||
textarea:focus {
|
||||
outline: none;
|
||||
border-color: #3498db;
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: vertical;
|
||||
min-height: 150px;
|
||||
}
|
||||
|
||||
.radio-group {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.radio-group label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-weight: normal;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button {
|
||||
background: #3498db;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 12px 24px;
|
||||
border-radius: 4px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background: #2980b9;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
background: #bdc3c7;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #95a5a6;
|
||||
padding: 8px 16px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background: #7f8c8d;
|
||||
}
|
||||
|
||||
.status {
|
||||
margin-top: 16px;
|
||||
padding: 12px;
|
||||
border-radius: 4px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.status.success {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
border: 1px solid #c3e6cb;
|
||||
}
|
||||
|
||||
.status.error {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
border: 1px solid #f5c6cb;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.history-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.history-header h2 {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.history-list {
|
||||
max-height: calc(100vh - 180px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.history-item {
|
||||
padding: 12px;
|
||||
border: 1px solid #eee;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 10px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.history-item.success {
|
||||
border-left: 4px solid #27ae60;
|
||||
}
|
||||
|
||||
.history-item.failed {
|
||||
border-left: 4px solid #e74c3c;
|
||||
}
|
||||
|
||||
.history-item-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.history-item-status {
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.history-item.success .history-item-status {
|
||||
color: #27ae60;
|
||||
}
|
||||
|
||||
.history-item.failed .history-item-status {
|
||||
color: #e74c3c;
|
||||
}
|
||||
|
||||
.history-item-date {
|
||||
font-size: 12px;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.history-item-to {
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.history-item-subject {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.history-item-error {
|
||||
font-size: 12px;
|
||||
color: #e74c3c;
|
||||
margin-top: 6px;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: #bbb;
|
||||
cursor: pointer;
|
||||
padding: 4px 8px;
|
||||
font-size: 16px;
|
||||
transition: color 0.2s;
|
||||
}
|
||||
|
||||
.delete-btn:hover {
|
||||
color: #e74c3c;
|
||||
background: none;
|
||||
}
|
||||
|
||||
.empty-message {
|
||||
text-align: center;
|
||||
color: #999;
|
||||
padding: 40px 20px;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.container {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.form-panel,
|
||||
.history-panel {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.history-list {
|
||||
max-height: 400px;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user