This is an HTML email with formatting.
- Feature 1
- Feature 2
- Feature 3
import { tap, expect } from '@git.zone/tstest/tapbundle'; import { startTestSmtpServer } from '../../helpers/server.loader.js'; import { createSmtpClient } from '../../helpers/smtp.client.js'; import { Email } from '../../../ts/mail/core/classes.email.js'; let testServer: any; tap.test('setup test SMTP server', async () => { testServer = await startTestSmtpServer(); expect(testServer).toBeTruthy(); expect(testServer.port).toBeGreaterThan(0); }); tap.test('CEP-07: Basic HTML email', async () => { const smtpClient = createSmtpClient({ host: testServer.hostname, port: testServer.port, secure: false, connectionTimeout: 5000, debug: true }); await smtpClient.connect(); // Create HTML email const email = new Email({ from: 'sender@example.com', to: ['recipient@example.com'], subject: 'HTML Email Test', html: `
This is an HTML email with formatting.
Here's an inline image:
And here's another one:
Product 1
Product 2
Product 3
© 2024 Example Corp
`, text: 'Monthly Newsletter - View in HTML for best experience', attachments: [ { filename: 'header-bg.jpg', content: Buffer.from('fake-image-data'), contentType: 'image/jpeg', cid: 'header-bg' }, { filename: 'logo.png', content: Buffer.from('fake-logo-data'), contentType: 'image/png', cid: 'logo' }, { filename: 'product1.jpg', content: Buffer.from('fake-product1-data'), contentType: 'image/jpeg', cid: 'product1' }, { filename: 'product2.jpg', content: Buffer.from('fake-product2-data'), contentType: 'image/jpeg', cid: 'product2' }, { filename: 'product3.jpg', content: Buffer.from('fake-product3-data'), contentType: 'image/jpeg', cid: 'product3' }, { filename: 'divider.gif', content: Buffer.from('fake-divider-data'), contentType: 'image/gif', cid: 'footer-divider' } ] }); // Count inline attachments let inlineAttachments = 0; let contentIds: string[] = []; const originalSendCommand = smtpClient.sendCommand.bind(smtpClient); smtpClient.sendCommand = async (command: string) => { if (command.toLowerCase().includes('content-disposition: inline')) { inlineAttachments++; } if (command.toLowerCase().includes('content-id:')) { const cidMatch = command.match(/content-id:\s*<([^>]+)>/i); if (cidMatch) { contentIds.push(cidMatch[1]); } } return originalSendCommand(command); }; const result = await smtpClient.sendMail(email); expect(result).toBeTruthy(); console.log(`Inline attachments: ${inlineAttachments}`); console.log(`Content-IDs found: ${contentIds.length}`); console.log('CIDs:', contentIds); // Should have all inline attachments expect(contentIds.length).toEqual(6); await smtpClient.close(); }); tap.test('CEP-07: HTML with external and inline images mixed', async () => { const smtpClient = createSmtpClient({ host: testServer.hostname, port: testServer.port, secure: false, connectionTimeout: 5000, debug: true }); await smtpClient.connect(); // Mix of inline and external images const email = new Email({ from: 'sender@example.com', to: ['recipient@example.com'], subject: 'Mixed Image Sources', html: `Left column content
Right column content
This text is hidden on mobile devices
This is safe text content.
Get 20% off with code: SPRING20
© 2024 Example Corp | Unsubscribe