@sibiltech/sibil-mail 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +3 -0
- package/README.md +2 -0
- package/dist/errors/sibil-mail-error.d.ts +41 -0
- package/dist/errors/sibil-mail-error.d.ts.map +1 -0
- package/dist/errors/sibil-mail-error.js +64 -0
- package/dist/errors/sibil-mail-error.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/sibil-mail.d.ts +123 -0
- package/dist/sibil-mail.d.ts.map +1 -0
- package/dist/sibil-mail.js +286 -0
- package/dist/sibil-mail.js.map +1 -0
- package/dist/test-connection-simple.d.ts +8 -0
- package/dist/test-connection-simple.d.ts.map +1 -0
- package/dist/test-connection-simple.js +96 -0
- package/dist/test-connection-simple.js.map +1 -0
- package/dist/test-email.d.ts +9 -0
- package/dist/test-email.d.ts.map +1 -0
- package/dist/test-email.js +124 -0
- package/dist/test-email.js.map +1 -0
- package/dist/test-server.d.ts +9 -0
- package/dist/test-server.d.ts.map +1 -0
- package/dist/test-server.js +140 -0
- package/dist/test-server.js.map +1 -0
- package/dist/transport.d.ts +37 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +194 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +64 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/email-validator.d.ts +51 -0
- package/dist/utils/email-validator.d.ts.map +1 -0
- package/dist/utils/email-validator.js +74 -0
- package/dist/utils/email-validator.js.map +1 -0
- package/dist/utils/template-engine.d.ts +51 -0
- package/dist/utils/template-engine.d.ts.map +1 -0
- package/dist/utils/template-engine.js +102 -0
- package/dist/utils/template-engine.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Simple Connection Test
|
|
4
|
+
*
|
|
5
|
+
* Direct test script to diagnose SMTP connection issues.
|
|
6
|
+
* Run with: npx ts-node src/test-connection-simple.ts
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const dotenv_1 = require("dotenv");
|
|
10
|
+
const sibil_mail_1 = require("./sibil-mail");
|
|
11
|
+
(0, dotenv_1.config)();
|
|
12
|
+
async function testConnection() {
|
|
13
|
+
console.log('🔍 Testing SMTP Connection...\n');
|
|
14
|
+
// Test configuration
|
|
15
|
+
const testConfigs = [
|
|
16
|
+
{
|
|
17
|
+
name: 'Gmail Port 587 (STARTTLS)',
|
|
18
|
+
config: {
|
|
19
|
+
host: 'smtp.gmail.com',
|
|
20
|
+
port: 587,
|
|
21
|
+
secure: false,
|
|
22
|
+
auth: {
|
|
23
|
+
user: process.env.SMTP_USER || '',
|
|
24
|
+
pass: process.env.SMTP_PASS || '',
|
|
25
|
+
},
|
|
26
|
+
tls: {
|
|
27
|
+
rejectUnauthorized: false, // Ignore TLS errors
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'Gmail Port 465 (SSL)',
|
|
33
|
+
config: {
|
|
34
|
+
host: 'smtp.gmail.com',
|
|
35
|
+
port: 465,
|
|
36
|
+
secure: true,
|
|
37
|
+
auth: {
|
|
38
|
+
user: process.env.SMTP_USER || '',
|
|
39
|
+
pass: process.env.SMTP_PASS || '',
|
|
40
|
+
},
|
|
41
|
+
tls: {
|
|
42
|
+
rejectUnauthorized: false,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'Gmail Service (Recommended)',
|
|
48
|
+
config: {
|
|
49
|
+
host: 'smtp.gmail.com',
|
|
50
|
+
port: 587,
|
|
51
|
+
secure: false,
|
|
52
|
+
auth: {
|
|
53
|
+
user: process.env.SMTP_USER || '',
|
|
54
|
+
pass: process.env.SMTP_PASS || '',
|
|
55
|
+
},
|
|
56
|
+
tls: {
|
|
57
|
+
rejectUnauthorized: false,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
for (const test of testConfigs) {
|
|
63
|
+
console.log(`Testing: ${test.name}`);
|
|
64
|
+
console.log(` Host: ${test.config.host}`);
|
|
65
|
+
console.log(` Port: ${test.config.port}`);
|
|
66
|
+
console.log(` Secure: ${test.config.secure}`);
|
|
67
|
+
console.log(` User: ${test.config.auth.user}`);
|
|
68
|
+
console.log(` Pass: ${test.config.auth.pass ? '***' : 'NOT SET'}\n`);
|
|
69
|
+
if (!test.config.auth.user || !test.config.auth.pass) {
|
|
70
|
+
console.log(' ⚠️ SMTP credentials not set in .env file\n');
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const mailer = new sibil_mail_1.SibilMail(test.config);
|
|
75
|
+
const result = await mailer.verifyConnection();
|
|
76
|
+
if (result) {
|
|
77
|
+
console.log(` ✅ SUCCESS! Connection verified.\n`);
|
|
78
|
+
await mailer.close();
|
|
79
|
+
return; // Stop on first success
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.log(` ❌ FAILED: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
84
|
+
console.log(` Full error:`, error);
|
|
85
|
+
console.log('');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
console.log('\n💡 Tips:');
|
|
89
|
+
console.log(' 1. Make sure you are using Gmail App Password (not regular password)');
|
|
90
|
+
console.log(' 2. Enable 2-Step Verification in your Google Account');
|
|
91
|
+
console.log(' 3. Check if port 587 or 465 is blocked by firewall');
|
|
92
|
+
console.log(' 4. Try from a different network');
|
|
93
|
+
console.log(' 5. Verify SMTP credentials in .env file');
|
|
94
|
+
}
|
|
95
|
+
testConnection().catch(console.error);
|
|
96
|
+
//# sourceMappingURL=test-connection-simple.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-connection-simple.js","sourceRoot":"","sources":["../src/test-connection-simple.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,mCAAgC;AAChC,6CAAyC;AAEzC,IAAA,eAAM,GAAE,CAAC;AAET,KAAK,UAAU,cAAc;IAC3B,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;IAE/C,qBAAqB;IACrB,MAAM,WAAW,GAAG;QAClB;YACE,IAAI,EAAE,2BAA2B;YACjC,MAAM,EAAE;gBACN,IAAI,EAAE,gBAAgB;gBACtB,IAAI,EAAE,GAAG;gBACT,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE;oBACJ,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE;oBACjC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE;iBAClC;gBACD,GAAG,EAAE;oBACH,kBAAkB,EAAE,KAAK,EAAE,oBAAoB;iBAChD;aACF;SACF;QACD;YACE,IAAI,EAAE,sBAAsB;YAC5B,MAAM,EAAE;gBACN,IAAI,EAAE,gBAAgB;gBACtB,IAAI,EAAE,GAAG;gBACT,MAAM,EAAE,IAAI;gBACZ,IAAI,EAAE;oBACJ,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE;oBACjC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE;iBAClC;gBACD,GAAG,EAAE;oBACH,kBAAkB,EAAE,KAAK;iBAC1B;aACF;SACF;QACD;YACE,IAAI,EAAE,6BAA6B;YACnC,MAAM,EAAE;gBACN,IAAI,EAAE,gBAAgB;gBACtB,IAAI,EAAE,GAAG;gBACT,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE;oBACJ,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE;oBACjC,IAAI,EAAE,OAAO,CA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wBAAwB;YAClC,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,GAAG,CAAC,eAAe,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACvF,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;YACpC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC1B,OAAO,CAAC,GAAG,CAAC,wEAAwE,CAAC,CAAC;IACtF,OAAO,CAAC,GAAG,CAAC,wDAAwD,CAAC,CAAC;IACtE,OAAO,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAC;IACpE,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IACjD,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;AAC3D,CAAC;AAED,cAAc,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-email.d.ts","sourceRoot":"","sources":["../src/test-email.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Test Email Script
|
|
4
|
+
*
|
|
5
|
+
* Simple script to test email sending functionality.
|
|
6
|
+
* Run with: npm run test:email
|
|
7
|
+
* Or: npx ts-node src/test-email.ts
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const dotenv_1 = require("dotenv");
|
|
11
|
+
const sibil_mail_1 = require("./sibil-mail");
|
|
12
|
+
const template_engine_1 = require("./utils/template-engine");
|
|
13
|
+
// Load environment variables
|
|
14
|
+
(0, dotenv_1.config)();
|
|
15
|
+
async function testEmail() {
|
|
16
|
+
console.log('🚀 Starting email test...\n');
|
|
17
|
+
// Create mailer instance from environment variables
|
|
18
|
+
const mailer = new sibil_mail_1.SibilMail({
|
|
19
|
+
host: process.env.SMTP_HOST || 'smtp.gmail.com',
|
|
20
|
+
port: parseInt(process.env.SMTP_PORT || '587', 10),
|
|
21
|
+
secure: process.env.SMTP_SECURE === 'true',
|
|
22
|
+
auth: {
|
|
23
|
+
user: process.env.SMTP_USER || '',
|
|
24
|
+
pass: process.env.SMTP_PASS || '',
|
|
25
|
+
},
|
|
26
|
+
tls: {
|
|
27
|
+
rejectUnauthorized: process.env.SMTP_IGNORE_TLS !== 'true',
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
// Verify connection
|
|
31
|
+
console.log('📡 Verifying SMTP connection...');
|
|
32
|
+
try {
|
|
33
|
+
const isConnected = await mailer.verifyConnection();
|
|
34
|
+
if (isConnected) {
|
|
35
|
+
console.log('✅ SMTP connection verified successfully!\n');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error('❌ SMTP connection failed:', error);
|
|
40
|
+
console.error('\nPlease check your SMTP configuration in .env file.');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// Test 1: Simple text email
|
|
44
|
+
console.log('📧 Test 1: Sending simple text email...');
|
|
45
|
+
const result1 = await mailer.send({
|
|
46
|
+
from: process.env.SMTP_FROM || process.env.SMTP_USER || '',
|
|
47
|
+
to: process.env.EMAIL_TO || process.env.SMTP_USER || '',
|
|
48
|
+
subject: 'Sibil Mail Test - Simple Text Email',
|
|
49
|
+
text: 'This is a simple test email from Sibil Mail library.\n\nIf you received this, the library is working correctly!',
|
|
50
|
+
});
|
|
51
|
+
if (result1.success) {
|
|
52
|
+
console.log('✅ Email sent successfully!');
|
|
53
|
+
console.log(' Message ID:', result1.messageId);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
console.error('❌ Failed to send email:', result1.error);
|
|
57
|
+
}
|
|
58
|
+
console.log('');
|
|
59
|
+
// Wait a bit before next email
|
|
60
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
61
|
+
// Test 2: HTML email with template
|
|
62
|
+
console.log('📧 Test 2: Sending HTML email with template...');
|
|
63
|
+
const htmlTemplate = (0, template_engine_1.createEmailTemplate)(`
|
|
64
|
+
<h1 style="color: #4f46e5;">Hello from Sibil Mail!</h1>
|
|
65
|
+
<p>This is a test email sent using the <strong>Sibil Mail</strong> library.</p>
|
|
66
|
+
<p>Features tested:</p>
|
|
67
|
+
<ul>
|
|
68
|
+
<li>✅ SMTP connection</li>
|
|
69
|
+
<li>✅ HTML email sending</li>
|
|
70
|
+
<li>✅ Template engine</li>
|
|
71
|
+
</ul>
|
|
72
|
+
<p style="color: #666; font-size: 12px;">This email was sent at {{timestamp}}</p>
|
|
73
|
+
`, {
|
|
74
|
+
styles: `
|
|
75
|
+
h1 { margin-top: 0; }
|
|
76
|
+
ul { padding-left: 20px; }
|
|
77
|
+
`,
|
|
78
|
+
});
|
|
79
|
+
const htmlContent = (0, template_engine_1.replaceVariables)(htmlTemplate, {
|
|
80
|
+
timestamp: new Date().toLocaleString(),
|
|
81
|
+
});
|
|
82
|
+
const result2 = await mailer.send({
|
|
83
|
+
from: process.env.SMTP_FROM || process.env.SMTP_USER || '',
|
|
84
|
+
to: process.env.EMAIL_TO || process.env.SMTP_USER || '',
|
|
85
|
+
subject: 'Sibil Mail Test - HTML Email with Template',
|
|
86
|
+
html: htmlContent,
|
|
87
|
+
text: 'This is a test email from Sibil Mail library. Please view in HTML format.',
|
|
88
|
+
});
|
|
89
|
+
if (result2.success) {
|
|
90
|
+
console.log('✅ HTML email sent successfully!');
|
|
91
|
+
console.log(' Message ID:', result2.messageId);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
console.error('❌ Failed to send HTML email:', result2.error);
|
|
95
|
+
}
|
|
96
|
+
console.log('');
|
|
97
|
+
// Test 3: Multiple recipients (if configured)
|
|
98
|
+
if (process.env.EMAIL_TO && process.env.EMAIL_TO.includes(',')) {
|
|
99
|
+
console.log('📧 Test 3: Sending email to multiple recipients...');
|
|
100
|
+
const recipients = process.env.EMAIL_TO.split(',').map((email) => email.trim());
|
|
101
|
+
const result3 = await mailer.send({
|
|
102
|
+
from: process.env.SMTP_FROM || process.env.SMTP_USER || '',
|
|
103
|
+
to: recipients,
|
|
104
|
+
subject: 'Sibil Mail Test - Multiple Recipients',
|
|
105
|
+
text: `This email was sent to ${recipients.length} recipient(s).`,
|
|
106
|
+
html: `<p>This email was sent to <strong>${recipients.length}</strong> recipient(s).</p>`,
|
|
107
|
+
});
|
|
108
|
+
if (result3.success) {
|
|
109
|
+
console.log('✅ Multiple recipients email sent successfully!');
|
|
110
|
+
console.log(' Message ID:', result3.messageId);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
console.error('❌ Failed to send email:', result3.error);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
console.log('\n✨ Email testing completed!');
|
|
117
|
+
console.log('📬 Check your inbox for the test emails.');
|
|
118
|
+
}
|
|
119
|
+
// Run test
|
|
120
|
+
testEmail().catch((error) => {
|
|
121
|
+
console.error('💥 Test failed with error:', error);
|
|
122
|
+
process.exit(1);
|
|
123
|
+
});
|
|
124
|
+
//# sourceMappingURL=test-email.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-email.js","sourceRoot":"","sources":["../src/test-email.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAEH,mCAAgC;AAChC,6CAAyC;AACzC,6DAAgF;AAEhF,6BAA6B;AAC7B,IAAA,eAAM,GAAE,CAAC;AAET,KAAK,UAAU,SAAS;IACtB,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;IAE3C,oDAAoD;IACpD,MAAM,MAAM,GAAG,IAAI,sBAAS,CAAC;QAC3B,IAAI,EAAE,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AC;IAC5C,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;AAC1D,CAAC;AAED,WAAW;AACX,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAC1B,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;IACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-server.d.ts","sourceRoot":"","sources":["../src/test-server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Test Server for Sibil Mail
|
|
4
|
+
*
|
|
5
|
+
* Simple Express server to test email functionality via web interface.
|
|
6
|
+
* Run with: npm run test:server
|
|
7
|
+
* Or: npx ts-node src/test-server.ts
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
const express_1 = __importDefault(require("express"));
|
|
14
|
+
const cors_1 = __importDefault(require("cors"));
|
|
15
|
+
const sibil_mail_1 = require("./sibil-mail");
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const app = (0, express_1.default)();
|
|
18
|
+
const PORT = 3001;
|
|
19
|
+
// Middleware
|
|
20
|
+
app.use((0, cors_1.default)());
|
|
21
|
+
app.use(express_1.default.json());
|
|
22
|
+
app.use(express_1.default.static(path_1.default.join(__dirname, '../public')));
|
|
23
|
+
// Serve HTML interface
|
|
24
|
+
app.get('/', (req, res) => {
|
|
25
|
+
res.sendFile(path_1.default.join(__dirname, '../public/index.html'));
|
|
26
|
+
});
|
|
27
|
+
// Test SMTP connection endpoint
|
|
28
|
+
app.post('/api/test-connection', async (req, res) => {
|
|
29
|
+
try {
|
|
30
|
+
const { config } = req.body;
|
|
31
|
+
if (!config || !config.host || !config.auth) {
|
|
32
|
+
return res.status(400).json({
|
|
33
|
+
success: false,
|
|
34
|
+
error: 'Invalid SMTP configuration',
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const mailer = new sibil_mail_1.SibilMail(config);
|
|
38
|
+
try {
|
|
39
|
+
const isConnected = await mailer.verifyConnection();
|
|
40
|
+
if (isConnected) {
|
|
41
|
+
res.json({
|
|
42
|
+
success: true,
|
|
43
|
+
message: 'SMTP connection verified successfully',
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
res.status(500).json({
|
|
48
|
+
success: false,
|
|
49
|
+
error: 'SMTP connection failed',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (verifyError) {
|
|
54
|
+
res.status(500).json({
|
|
55
|
+
success: false,
|
|
56
|
+
error: verifyError instanceof Error ? verifyError.message : 'SMTP connection failed',
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
// Close connection
|
|
61
|
+
await mailer.close().catch(() => { });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
res.status(500).json({
|
|
66
|
+
success: false,
|
|
67
|
+
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
// Send email endpoint
|
|
72
|
+
app.post('/api/send-email', async (req, res) => {
|
|
73
|
+
try {
|
|
74
|
+
const { config, email } = req.body;
|
|
75
|
+
if (!config || !config.host || !config.auth) {
|
|
76
|
+
return res.status(400).json({
|
|
77
|
+
success: false,
|
|
78
|
+
error: 'Invalid SMTP configuration',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (!email || !email.from || !email.to || !email.subject) {
|
|
82
|
+
return res.status(400).json({
|
|
83
|
+
success: false,
|
|
84
|
+
error: 'Missing required email fields (from, to, subject)',
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const mailer = new sibil_mail_1.SibilMail(config);
|
|
88
|
+
// Prepare email options
|
|
89
|
+
const emailOptions = {
|
|
90
|
+
from: email.from,
|
|
91
|
+
to: email.to,
|
|
92
|
+
subject: email.subject,
|
|
93
|
+
};
|
|
94
|
+
// Add body based on type
|
|
95
|
+
if (email.type === 'text' || email.type === 'both') {
|
|
96
|
+
emailOptions.text = email.message;
|
|
97
|
+
}
|
|
98
|
+
if (email.type === 'html' || email.type === 'both') {
|
|
99
|
+
// Convert plain text to simple HTML
|
|
100
|
+
emailOptions.html = email.message
|
|
101
|
+
.replace(/\n/g, '<br>')
|
|
102
|
+
.replace(/^(.+)$/gm, '<p>$1</p>');
|
|
103
|
+
}
|
|
104
|
+
// Send email
|
|
105
|
+
const result = await mailer.send(emailOptions);
|
|
106
|
+
if (result.success) {
|
|
107
|
+
res.json({
|
|
108
|
+
success: true,
|
|
109
|
+
messageId: result.messageId,
|
|
110
|
+
response: result.response,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
res.status(500).json({
|
|
115
|
+
success: false,
|
|
116
|
+
error: result.error || 'Failed to send email',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
// Close connection after sending
|
|
120
|
+
await mailer.close().catch(() => { });
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
res.status(500).json({
|
|
124
|
+
success: false,
|
|
125
|
+
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
// Health check endpoint
|
|
130
|
+
app.get('/api/health', (req, res) => {
|
|
131
|
+
res.json({ status: 'ok', service: 'Sibil Mail Test Server' });
|
|
132
|
+
});
|
|
133
|
+
// Start server
|
|
134
|
+
app.listen(PORT, () => {
|
|
135
|
+
console.log('🚀 Sibil Mail Test Server is running!');
|
|
136
|
+
console.log(`📧 Web Interface: http://localhost:${PORT}`);
|
|
137
|
+
console.log(`🔌 API Endpoint: http://localhost:${PORT}/api`);
|
|
138
|
+
console.log('\nPress Ctrl+C to stop the server.\n');
|
|
139
|
+
});
|
|
140
|
+
//# sourceMappingURL=test-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-server.js","sourceRoot":"","sources":["../src/test-server.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;AAEH,sDAA8B;AAC9B,gDAAwB;AACxB,6CAAyC;AAEzC,gDAAwB;AAExB,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;AACtB,MAAM,IAAI,GAAG,IAAI,CAAC;AAElB,aAAa;AACb,GAAG,CAAC,GAAG,CAAC,IAAA,cAAI,GAAE,CAAC,CAAC;AAChB,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AACxB,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,MAAM,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;AAE3D,uBAAuB;AACvB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACxB,GAAG,CAAC,QAAQ,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC,CAAC;AAC7D,CAAC,CAAC,CAAC;AAEH,gCAAgC;AAChC,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;IAClD,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAA2B,GAAG,CAAC,IAAI,CAAC;QAEpD,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5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IAAI,EAAE,GAAG,EAAE;IACpB,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;IACrD,OAAO,CAAC,GAAG,CAAC,sCAAsC,IAAI,EAAE,CAAC,CAAC;IAC1D,OAAO,CAAC,GAAG,CAAC,qCAAqC,IAAI,MAAM,CAAC,CAAC;IAC7D,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;AACtD,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SMTP Transport Factory
|
|
3
|
+
*
|
|
4
|
+
* Professional SMTP transport configuration with comprehensive error handling
|
|
5
|
+
* and support for various SMTP providers (Gmail, Outlook, Yahoo, etc.)
|
|
6
|
+
*/
|
|
7
|
+
import { Transporter } from 'nodemailer';
|
|
8
|
+
import { SmtpConfig } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* Create SMTP Transport
|
|
11
|
+
*
|
|
12
|
+
* Creates a professionally configured nodemailer transporter.
|
|
13
|
+
* Uses simplified configuration for maximum compatibility.
|
|
14
|
+
*
|
|
15
|
+
* @param config - SMTP configuration object
|
|
16
|
+
* @returns Configured nodemailer transporter
|
|
17
|
+
*/
|
|
18
|
+
export declare function createSmtpTransport(config: SmtpConfig): Transporter;
|
|
19
|
+
/**
|
|
20
|
+
* Verify SMTP Connection
|
|
21
|
+
*
|
|
22
|
+
* Tests the SMTP connection with comprehensive error handling.
|
|
23
|
+
*
|
|
24
|
+
* @param transporter - Nodemailer transporter instance
|
|
25
|
+
* @returns Promise that resolves if connection is valid
|
|
26
|
+
* @throws Error with detailed message if connection fails
|
|
27
|
+
*/
|
|
28
|
+
export declare function verifySmtpConnection(transporter: Transporter): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Close Transport Connection
|
|
31
|
+
*
|
|
32
|
+
* Properly closes the transporter connection pool.
|
|
33
|
+
*
|
|
34
|
+
* @param transporter - Nodemailer transporter instance
|
|
35
|
+
*/
|
|
36
|
+
export declare function closeTransport(transporter: Transporter): Promise<void>;
|
|
37
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAmB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAcrC;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,UAAU,GAAG,WAAW,CA0EnE;AAED;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAsElF;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAM5E"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SMTP Transport Factory
|
|
4
|
+
*
|
|
5
|
+
* Professional SMTP transport configuration with comprehensive error handling
|
|
6
|
+
* and support for various SMTP providers (Gmail, Outlook, Yahoo, etc.)
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createSmtpTransport = createSmtpTransport;
|
|
13
|
+
exports.verifySmtpConnection = verifySmtpConnection;
|
|
14
|
+
exports.closeTransport = closeTransport;
|
|
15
|
+
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
16
|
+
/**
|
|
17
|
+
* Detect SMTP Provider
|
|
18
|
+
* Automatically detects common email providers and applies optimal settings
|
|
19
|
+
*/
|
|
20
|
+
function detectProvider(host) {
|
|
21
|
+
const hostLower = host.toLowerCase();
|
|
22
|
+
if (hostLower.includes('gmail.com'))
|
|
23
|
+
return 'gmail';
|
|
24
|
+
if (hostLower.includes('outlook.com') || hostLower.includes('hotmail.com') || hostLower.includes('live.com'))
|
|
25
|
+
return 'outlook';
|
|
26
|
+
if (hostLower.includes('yahoo.com'))
|
|
27
|
+
return 'yahoo';
|
|
28
|
+
return 'custom';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create SMTP Transport
|
|
32
|
+
*
|
|
33
|
+
* Creates a professionally configured nodemailer transporter.
|
|
34
|
+
* Uses simplified configuration for maximum compatibility.
|
|
35
|
+
*
|
|
36
|
+
* @param config - SMTP configuration object
|
|
37
|
+
* @returns Configured nodemailer transporter
|
|
38
|
+
*/
|
|
39
|
+
function createSmtpTransport(config) {
|
|
40
|
+
const provider = detectProvider(config.host);
|
|
41
|
+
const port = config.port;
|
|
42
|
+
const ignoreTLS = config.tls?.rejectUnauthorized === false;
|
|
43
|
+
// For Gmail, use the simplest possible configuration
|
|
44
|
+
if (provider === 'gmail' && (port === 587 || port === 465)) {
|
|
45
|
+
const gmailConfig = {
|
|
46
|
+
service: 'gmail',
|
|
47
|
+
auth: {
|
|
48
|
+
user: config.auth.user.trim(),
|
|
49
|
+
pass: config.auth.pass.trim(),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
// Only add TLS config if we need to ignore certificate errors
|
|
53
|
+
if (ignoreTLS) {
|
|
54
|
+
gmailConfig.tls = {
|
|
55
|
+
rejectUnauthorized: false,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return nodemailer_1.default.createTransport(gmailConfig);
|
|
59
|
+
}
|
|
60
|
+
// For other providers or custom ports, use host/port configuration
|
|
61
|
+
const isSecurePort = port === 465;
|
|
62
|
+
const useSecure = config.secure ?? isSecurePort;
|
|
63
|
+
const useStartTLS = !useSecure && (port === 587 || port === 25);
|
|
64
|
+
const transportConfig = {
|
|
65
|
+
host: config.host,
|
|
66
|
+
port: port,
|
|
67
|
+
secure: useSecure,
|
|
68
|
+
auth: {
|
|
69
|
+
user: config.auth.user.trim(),
|
|
70
|
+
pass: config.auth.pass.trim(),
|
|
71
|
+
},
|
|
72
|
+
connectionTimeout: 60000,
|
|
73
|
+
greetingTimeout: 30000,
|
|
74
|
+
socketTimeout: 60000,
|
|
75
|
+
pool: false,
|
|
76
|
+
debug: false,
|
|
77
|
+
logger: false,
|
|
78
|
+
};
|
|
79
|
+
// TLS/SSL Configuration - simplified
|
|
80
|
+
if (useSecure) {
|
|
81
|
+
// SSL mode (port 465)
|
|
82
|
+
transportConfig.tls = {
|
|
83
|
+
rejectUnauthorized: !ignoreTLS,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
else if (useStartTLS) {
|
|
87
|
+
// STARTTLS mode (port 587, 25)
|
|
88
|
+
transportConfig.requireTLS = true;
|
|
89
|
+
transportConfig.tls = {
|
|
90
|
+
rejectUnauthorized: !ignoreTLS,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
else if (ignoreTLS) {
|
|
94
|
+
// Optional TLS with ignore
|
|
95
|
+
transportConfig.tls = {
|
|
96
|
+
rejectUnauthorized: false,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
// Create transporter
|
|
100
|
+
const transporter = nodemailer_1.default.createTransport(transportConfig);
|
|
101
|
+
// Add error event listeners for better debugging
|
|
102
|
+
transporter.on('error', (error) => {
|
|
103
|
+
console.error('SMTP Transport Error:', error);
|
|
104
|
+
});
|
|
105
|
+
return transporter;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Verify SMTP Connection
|
|
109
|
+
*
|
|
110
|
+
* Tests the SMTP connection with comprehensive error handling.
|
|
111
|
+
*
|
|
112
|
+
* @param transporter - Nodemailer transporter instance
|
|
113
|
+
* @returns Promise that resolves if connection is valid
|
|
114
|
+
* @throws Error with detailed message if connection fails
|
|
115
|
+
*/
|
|
116
|
+
async function verifySmtpConnection(transporter) {
|
|
117
|
+
try {
|
|
118
|
+
await transporter.verify();
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
// Provide more detailed error messages
|
|
122
|
+
if (error instanceof Error) {
|
|
123
|
+
const errorMessage = error.message.toLowerCase();
|
|
124
|
+
const fullError = error.message;
|
|
125
|
+
// Log full error for debugging
|
|
126
|
+
console.error('SMTP Verification Error Details:', {
|
|
127
|
+
message: error.message,
|
|
128
|
+
code: error.code,
|
|
129
|
+
errno: error.errno,
|
|
130
|
+
syscall: error.syscall,
|
|
131
|
+
hostname: error.hostname,
|
|
132
|
+
port: error.port,
|
|
133
|
+
});
|
|
134
|
+
// Authentication errors
|
|
135
|
+
if (errorMessage.includes('invalid login') ||
|
|
136
|
+
errorMessage.includes('authentication failed') ||
|
|
137
|
+
errorMessage.includes('535') ||
|
|
138
|
+
errorMessage.includes('invalid credentials')) {
|
|
139
|
+
throw new Error('Authentication failed: Invalid email or password. For Gmail, make sure you are using an App Password (not your regular password) and that 2-Step Verification is enabled.');
|
|
140
|
+
}
|
|
141
|
+
// Connection refused errors
|
|
142
|
+
if (errorMessage.includes('econnrefused') ||
|
|
143
|
+
errorMessage.includes('connection refused') ||
|
|
144
|
+
error.code === 'ECONNREFUSED') {
|
|
145
|
+
throw new Error(`Connection refused: Cannot connect to SMTP server. Check if the host and port are correct.`);
|
|
146
|
+
}
|
|
147
|
+
// Timeout errors
|
|
148
|
+
if (errorMessage.includes('timeout') ||
|
|
149
|
+
errorMessage.includes('etimedout') ||
|
|
150
|
+
error.code === 'ETIMEDOUT') {
|
|
151
|
+
throw new Error(`Connection timeout: Server did not respond in time. Check your network connection and firewall settings.`);
|
|
152
|
+
}
|
|
153
|
+
// TLS/SSL errors
|
|
154
|
+
if (errorMessage.includes('tls') ||
|
|
155
|
+
errorMessage.includes('ssl') ||
|
|
156
|
+
errorMessage.includes('certificate') ||
|
|
157
|
+
errorMessage.includes('handshake') ||
|
|
158
|
+
errorMessage.includes('socket disconnected')) {
|
|
159
|
+
throw new Error(`TLS/SSL error: ${fullError}. Solutions: 1) Make sure "Ignore TLS Certificate Errors" is enabled, 2) Try port 465 with SSL enabled, 3) Check firewall/antivirus settings, 4) Try from a different network.`);
|
|
160
|
+
}
|
|
161
|
+
// Socket errors
|
|
162
|
+
if (errorMessage.includes('socket') ||
|
|
163
|
+
errorMessage.includes('disconnected') ||
|
|
164
|
+
errorMessage.includes('econnreset')) {
|
|
165
|
+
throw new Error(`Network error: ${fullError}. The connection was reset. This might be due to firewall blocking or network issues.`);
|
|
166
|
+
}
|
|
167
|
+
// DNS errors
|
|
168
|
+
if (errorMessage.includes('enotfound') ||
|
|
169
|
+
errorMessage.includes('dns') ||
|
|
170
|
+
error.code === 'ENOTFOUND') {
|
|
171
|
+
throw new Error(`DNS error: Cannot resolve hostname. Check if the SMTP host address is correct.`);
|
|
172
|
+
}
|
|
173
|
+
// Return original error with context
|
|
174
|
+
throw new Error(`SMTP verification failed: ${fullError}`);
|
|
175
|
+
}
|
|
176
|
+
throw new Error('SMTP verification failed: Unknown error occurred');
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Close Transport Connection
|
|
181
|
+
*
|
|
182
|
+
* Properly closes the transporter connection pool.
|
|
183
|
+
*
|
|
184
|
+
* @param transporter - Nodemailer transporter instance
|
|
185
|
+
*/
|
|
186
|
+
async function closeTransport(transporter) {
|
|
187
|
+
try {
|
|
188
|
+
transporter.close();
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
console.error('Error closing transport:', error);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AA0BH,kDA0EC;AAWD,oDAsEC;AASD,wCAMC;AAlMD,4DAAqD;AAGrD;;;GAGG;AACH,SAAS,cAAc,CAAC,IAAY;IAClC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