Skip to content

Commit e63f212

Browse files
smbeckerscopsy
andauthored
feat(providers): Add support for using embedded images in email providers (#5457)
Co-authored-by: Dima Grossman <[email protected]>
1 parent 906cefa commit e63f212

File tree

10 files changed

+57
-15
lines changed

10 files changed

+57
-15
lines changed

packages/providers/src/lib/email/emailjs/emailjs.provider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export class EmailJsProvider extends BaseProvider implements IEmailProvider {
8686
name: attachment.name,
8787
data: attachment.file.toString('base64'),
8888
type: attachment.mime,
89+
inline: Boolean(attachment.cid),
8990
};
9091
})
9192
: [];

packages/providers/src/lib/email/mailersend/mailersend.provider.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ export class MailersendEmailProvider extends BaseProvider implements IEmailProvi
3636
}
3737

3838
private getAttachments(attachments: IEmailOptions['attachments']): Attachment[] | null {
39-
return attachments?.map((attachment) => new Attachment(attachment.file.toString('base64'), attachment.name));
39+
return attachments?.map(
40+
(attachment) =>
41+
new Attachment(
42+
attachment.file.toString('base64'),
43+
attachment.name,
44+
attachment.disposition ?? (attachment.cid ? 'inline' : 'attachment'),
45+
attachment.cid
46+
)
47+
);
4048
}
4149

4250
private createMailData(options: IEmailOptions): EmailParams {

packages/providers/src/lib/email/mailgun/mailgun.provider.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,22 @@ export class MailgunEmailProvider extends BaseProvider implements IEmailProvider
7373
html: emailOptions.html,
7474
cc: emailOptions.cc?.join(','),
7575
bcc: emailOptions.bcc?.join(','),
76-
attachment: emailOptions.attachments?.map((attachment) => {
77-
return {
78-
data: attachment.file,
79-
filename: attachment.name,
80-
};
81-
}),
76+
attachment: emailOptions.attachments
77+
?.filter((attachment) => !attachment.cid)
78+
?.map((attachment) => {
79+
return {
80+
data: attachment.file,
81+
filename: attachment.name,
82+
};
83+
}),
84+
inline: emailOptions.attachments
85+
?.filter((attachment) => Boolean(attachment.cid))
86+
?.map((attachment) => {
87+
return {
88+
data: attachment.file,
89+
filename: attachment.name,
90+
};
91+
}),
8292
};
8393

8494
if (emailOptions.replyTo) {

packages/providers/src/lib/email/mailjet/mailjet.provider.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,21 @@ export class MailjetEmailProvider extends BaseProvider implements IEmailProvider
103103
Subject: options.subject,
104104
TextPart: options.text,
105105
HTMLPart: options.html,
106-
Attachments: options.attachments?.map((attachment) => ({
107-
ContentType: attachment.mime,
108-
Filename: attachment.name,
109-
Base64Content: attachment.file.toString('base64'),
110-
})),
106+
Attachments: options.attachments
107+
?.filter((attachment) => !attachment.cid)
108+
?.map((attachment) => ({
109+
ContentType: attachment.mime,
110+
Filename: attachment.name,
111+
Base64Content: attachment.file.toString('base64'),
112+
})),
113+
InlinedAttachments: options.attachments
114+
?.filter((attachment) => attachment.cid)
115+
?.map((attachment) => ({
116+
ContentType: attachment.mime,
117+
Filename: attachment.name,
118+
Base64Content: attachment.file.toString('base64'),
119+
ContentID: attachment.cid,
120+
})),
111121
}).body;
112122

113123
if (options.replyTo) {

packages/providers/src/lib/email/mailtrap/mailtrap.provider.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ICheckIntegrationResponse,
88
CheckIntegrationResponseEnum,
99
} from '@novu/stateless';
10-
import { MailtrapClient, Address, Mail } from 'mailtrap';
10+
import { MailtrapClient, Address, Mail, Attachment } from 'mailtrap';
1111
import { BaseProvider, CasingEnum } from '../../../base.provider';
1212
import { WithPassthrough } from '../../../utils/types';
1313

@@ -73,6 +73,7 @@ export class MailtrapEmailProvider extends BaseProvider implements IEmailProvide
7373
filename: attachment.name,
7474
content: attachment.file,
7575
type: attachment.mime,
76+
content_id: attachment.cid,
7677
})),
7778
}).body
7879
);

packages/providers/src/lib/email/nodemailer/nodemailer.provider.ts

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ export class NodemailerProvider extends BaseProvider implements IEmailProvider {
139139
filename: attachment?.name,
140140
content: attachment.file,
141141
contentType: attachment.mime,
142+
cid: attachment.cid,
143+
contentDisposition:
144+
(attachment.disposition as 'inline' | 'attachment') ?? (attachment.cid ? 'inline' : undefined),
142145
})),
143146
bcc: options.bcc,
144147
};

packages/providers/src/lib/email/outlook365/outlook365.provider.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ export class Outlook365Provider extends BaseProvider implements IEmailProvider {
8383
html: options.html,
8484
text: options.text,
8585
attachments: options.attachments?.map((attachment) => ({
86-
filename: attachment?.name,
86+
filename: attachment.name,
8787
content: attachment.file,
8888
contentType: attachment.mime,
89+
cid: attachment.cid,
90+
contentDisposition:
91+
(attachment.disposition as 'inline' | 'attachment') ?? (attachment.cid ? 'inline' : undefined),
8992
})),
9093
};
9194

packages/providers/src/lib/email/postmark/postmark.provider.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export class PostmarkEmailProvider extends BaseProvider implements IEmailProvide
8181
Cc: getFormattedTo(options.cc),
8282
Bcc: getFormattedTo(options.bcc),
8383
Attachments: options.attachments?.map(
84-
(attachment) => new Models.Attachment(attachment.name, attachment.file.toString('base64'), attachment.mime)
84+
(attachment) =>
85+
new Models.Attachment(attachment.name, attachment.file.toString('base64'), attachment.mime, attachment.cid)
8586
),
8687
};
8788

packages/providers/src/lib/email/sendgrid/sendgrid.provider.ts

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ export class SendgridEmailProvider extends BaseProvider implements IEmailProvide
9797

9898
if (attachment?.disposition) {
9999
attachmentJson.disposition = attachment?.disposition;
100+
} else if (attachment?.cid) {
101+
attachmentJson.disposition = 'inline';
100102
}
101103

102104
return attachmentJson;

packages/providers/src/lib/email/ses/ses.provider.ts

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ export class SESEmailProvider extends BaseProvider implements IEmailProvider {
7474
filename: attachment?.name,
7575
content: attachment.file,
7676
contentType: attachment.mime,
77+
cid: attachment.cid,
78+
contentDisposition:
79+
attachment.disposition ?? (attachment.cid ? 'inline' : undefined),
7780
})),
7881
cc,
7982
bcc,

0 commit comments

Comments
 (0)