Files
emailjs/scripts/send-attachment.js
eleith 1544f0300f style: normalize formatting before adopting Oxfmt
Apply the existing tabs, quotes, semicolon, and line-width conventions across source, tests, examples, documentation, and configuration. Include Oxfmt's parentheses around a conditional type without changing behavior.
2026-10-26 14:49:11 -07:00

42 lines
1.1 KiB
JavaScript

import { Message } from '../dist/index.js'
import { getMailpitClient } from './mailpit-client.js'
async function sendAttachmentEmail() {
const client = getMailpitClient()
const attachmentContent = `This is the content of the attached file.
It can be anything you want to attach.
Timestamp: ${new Date().toISOString()}`
const message = new Message({
from: 'sender@example.com',
to: 'recipient@example.com',
subject: 'Test Email with Attachment to Mailpit',
text: 'Please find the attachment.',
attachment: [
{
data: attachmentContent,
type: 'text/plain',
name: 'attachment.txt',
},
{
path: 'test/attachments/smtp.pdf', // Using an existing fixture for a real file attachment
type: 'application/pdf',
name: 'document.pdf',
},
],
})
try {
console.log('Attempting to send email with attachment...')
await client.sendAsync(message)
console.log('Email with attachment sent successfully to Mailpit!')
} catch (error) {
console.error('Failed to send email with attachment:', error)
} finally {
client.smtp.close()
}
}
sendAttachmentEmail()