Skip to content

Commit 45d9abc

Browse files
committed
feat: add support for inline attachments in email requests
- Extended `attach` method to support optional `content_id` for inline attachments. - Updated tests to verify content_id functionality. - Updated README with documentation and examples for inline attachments.
1 parent a9ed115 commit 45d9abc

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const response = await lettermint.email
5555
'X-Custom-Header': 'Custom Value',
5656
})
5757
.attach('attachment.txt', Buffer.from('Hello World').toString('base64'))
58+
.attach('logo.png', Buffer.from('...').toString('base64'), 'logo') // Inline attachment
5859
.idempotencyKey('unique-id-123')
5960
.metadata({
6061
foo: 'bar',
@@ -90,7 +91,7 @@ Methods for sending emails:
9091
- `bcc(...emails: string[])`: Set one or more BCC email addresses
9192
- `replyTo(...emails: string[])`: Set one or more Reply-To email addresses
9293
- `headers(headers: Record<string, string>)`: Set custom headers for the email
93-
- `attach(filename: string, base64Content: string)`: Attach a file to the email
94+
- `attach(filename: string, base64Content: string, content_id?: string)`: Attach a file to the email. Optional `content_id` for inline attachments.
9495
- `route(route: string)`: Set the routing key for the email
9596
- `idempotencyKey(key: string)`: Set an idempotency key to prevent duplicate email sends
9697
- `metadata(metadata: Record<string, string>)`: Set metadata for the email

src/endpoints/email.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,28 @@ describe('EmailEndpoint', () => {
187187
});
188188
});
189189

190+
it('should add attachments with content_id', () => {
191+
const result = emailEndpoint.attach('image.png', 'base64imagedata', 'logo');
192+
193+
expect(result).toBe(emailEndpoint);
194+
195+
return emailEndpoint.send().then(() => {
196+
expect(client.post).toHaveBeenCalledWith(
197+
'/send',
198+
expect.objectContaining({
199+
attachments: [
200+
{
201+
filename: 'image.png',
202+
content: 'base64imagedata',
203+
content_id: 'logo',
204+
},
205+
],
206+
}),
207+
undefined
208+
);
209+
});
210+
});
211+
190212
it('should set the route', () => {
191213
const result = emailEndpoint.route('test-route');
192214

src/endpoints/email.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export interface EmailAttachment {
1313
* The base64-encoded content of the attachment
1414
*/
1515
content: string;
16+
17+
/**
18+
* The Content-ID for inline attachments (optional)
19+
*/
20+
content_id?: string;
1621
}
1722

1823
/**
@@ -279,16 +284,18 @@ export class EmailEndpoint extends Endpoint {
279284
*
280285
* @param filename The attachment filename
281286
* @param content The base64-encoded file content
287+
* @param content_id The Content-ID for inline attachments (optional)
282288
* @returns The current instance for chaining
283289
*/
284-
public attach(filename: string, content: string): this {
290+
public attach(filename: string, content: string, content_id?: string): this {
285291
if (!this.payload.attachments) {
286292
this.payload.attachments = [];
287293
}
288294

289295
this.payload.attachments.push({
290296
filename,
291297
content,
298+
...(content_id && { content_id }),
292299
});
293300

294301
return this;

0 commit comments

Comments
 (0)