This repository was archived by the owner on Aug 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmailgun-detailed-test.cjs
More file actions
91 lines (76 loc) · 2.93 KB
/
Copy pathmailgun-detailed-test.cjs
File metadata and controls
91 lines (76 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Detailed Mailgun test script
const dotenv = require('dotenv');
dotenv.config();
async function testMailgun() {
console.log('=== Detailed Mailgun Test ===');
// Check configuration
const apiKey = process.env.MAILGUN_API_KEY;
const domain = process.env.MAILGUN_DOMAIN;
console.log(`API Key: ${apiKey ? '✓ Set' : '✗ Not set'}`);
console.log(`Domain: ${domain || '✗ Not set'}`);
if (!apiKey || !domain) {
console.log('❌ Cannot proceed: Missing configuration');
return;
}
try {
const formData = require('form-data');
const Mailgun = require('mailgun.js');
console.log('\nInitializing Mailgun client...');
const mailgun = new Mailgun(formData);
const mg = mailgun.client({
username: 'api',
key: apiKey
});
// Test domain verification status
console.log('\nChecking domain verification status...');
try {
const domainInfo = await mg.domains.get(domain);
console.log(`Domain exists: ✓`);
console.log(`Domain state: ${domainInfo.state || 'unknown'}`);
console.log(`Receiving records setup: ${domainInfo.receiving_dns_records ? '✓' : '✗'}`);
console.log(`Sending records setup: ${domainInfo.sending_dns_records ? '✓' : '✗'}`);
} catch (domainError) {
console.error(`❌ Failed to get domain info: ${domainError.message}`);
}
// Try sending a test email
console.log('\nAttempting to send test email...');
try {
const testEmail = 'dealappseo@gmail.com';
console.log(`Sending to: ${testEmail}`);
const result = await mg.messages.create(
domain,
{
from: `HyperDAG <noreply@${domain}>`,
to: [testEmail],
subject: 'HyperDAG Mailgun Detailed Test',
text: 'This is a detailed test email from HyperDAG via Mailgun.',
html: `
<div style="font-family: Arial; padding: 20px; max-width: 600px; margin: 0 auto; border: 1px solid #ddd; border-radius: 5px;">
<h2 style="color: #333;">HyperDAG Mailgun Test</h2>
<p>This is a detailed test email sent via Mailgun.</p>
<p><strong>Timestamp:</strong> ${new Date().toLocaleString()}</p>
<p><strong>Domain:</strong> ${domain}</p>
</div>
`
}
);
console.log('✅ Email sent successfully!');
console.log(`Message ID: ${result.id}`);
} catch (sendError) {
console.error('❌ Failed to send email:');
console.error(sendError.message);
// More detailed error information
if (sendError.status) {
console.error(`Status code: ${sendError.status}`);
}
if (sendError.details) {
console.error('Error details:', sendError.details);
}
}
} catch (error) {
console.error('❌ General error:');
console.error(error.message);
}
console.log('\n=== Test Complete ===');
}
testMailgun().catch(console.error);