Skip to content

Commit bfcffe4

Browse files
lucasra1bjarn
authored andcommitted
feat: add contentType parameter to Attachment and EmailEndpoint.attach method
1 parent 4af80d8 commit bfcffe4

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/main/java/co/lettermint/endpoints/EmailEndpoint.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,20 @@ public EmailEndpoint attach(String filename, String content) {
151151
* @param contentId Content-ID for inline attachments (e.g., for embedding images)
152152
*/
153153
public EmailEndpoint attach(String filename, String content, String contentId) {
154-
this.attachments.add(new Attachment(filename, content, contentId));
154+
this.attachments.add(new Attachment(filename, content, contentId, null));
155+
return this;
156+
}
157+
158+
/**
159+
* Attach an inline file to the email and specify the {@code Content-Type}
160+
*
161+
* @param filename The filename to use for the attachment
162+
* @param content Base64-encoded file content
163+
* @param contentId Content-ID for inline attachments (e.g., for embedding images)
164+
* @param contentType MIME type of the attachment (e.g., "image/png")
165+
*/
166+
public EmailEndpoint attach(String filename, String content, String contentId, String contentType) {
167+
this.attachments.add(new Attachment(filename, content, contentId, contentType));
155168
return this;
156169
}
157170

src/main/java/co/lettermint/models/Attachment.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ public class Attachment {
1818
@JsonProperty("content_id")
1919
private final String contentId;
2020

21+
@JsonProperty("content_type")
22+
private final String contentType;
23+
2124
public Attachment(String filename, String content) {
22-
this(filename, content, null);
25+
this(filename, content, null, null);
2326
}
2427

25-
public Attachment(String filename, String content, String contentId) {
28+
public Attachment(String filename, String content, String contentId, String contentType) {
2629
this.filename = filename;
2730
this.content = content;
2831
this.contentId = contentId;
32+
this.contentType = contentType;
2933
}
3034

3135
public String getFilename() {
@@ -39,4 +43,8 @@ public String getContent() {
3943
public String getContentId() {
4044
return contentId;
4145
}
46+
47+
public String getContentType() {
48+
return contentType;
49+
}
4250
}

src/test/java/co/lettermint/EmailEndpointTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ void testEmailWithAllOptions() throws Exception {
8181
.headers(headers)
8282
.attach("document.pdf", "base64content")
8383
.attach("logo.png", "base64logo", "logo-cid")
84+
.attach("invite.ics", "base64icalFile", null, "text/calendar; method=REQUEST")
8485
.route("route-slug-123")
8586
.metadata(metadata)
8687
.tag("welcome", "onboarding")
@@ -103,6 +104,9 @@ void testEmailWithAllOptions() throws Exception {
103104
assertTrue(body.contains("\"text\":\"Hello World\""));
104105
assertTrue(body.contains("\"route\":\"route-slug-123\""));
105106
assertTrue(body.contains("\"tags\":[\"welcome\",\"onboarding\"]"));
107+
assertTrue(body.contains("{\"filename\":\"document.pdf\",\"content\":\"base64content\"}"));
108+
assertTrue(body.contains("{\"filename\":\"logo.png\",\"content\":\"base64logo\",\"content_id\":\"logo-cid\"}"));
109+
assertTrue(body.contains("{\"filename\":\"invite.ics\",\"content\":\"base64icalFile\",\"content_type\":\"text/calendar; method=REQUEST\"}"));
106110
}
107111

108112
@Test

0 commit comments

Comments
 (0)