Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/main/java/co/lettermint/endpoints/EmailEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class EmailEndpoint extends Endpoint {
private List<String> to;
private List<String> cc;
private List<String> bcc;
private String replyTo;
private List<String> replyTo;
private String subject;
private String html;
private String text;
Expand All @@ -39,7 +39,7 @@ private void reset() {
this.to = new ArrayList<>();
this.cc = new ArrayList<>();
this.bcc = new ArrayList<>();
this.replyTo = null;
this.replyTo = new ArrayList<>();
this.subject = null;
this.html = null;
this.text = null;
Expand Down Expand Up @@ -85,10 +85,10 @@ public EmailEndpoint bcc(String... emails) {
}

/**
* Set the reply-to email address.
* Set reply-to email addresses. Replaces any existing reply-to addresses.
*/
public EmailEndpoint replyTo(String replyTo) {
this.replyTo = replyTo;
public EmailEndpoint replyTo(String... emails) {
this.replyTo = new ArrayList<>(Arrays.asList(emails));
return this;
}

Expand Down Expand Up @@ -233,7 +233,7 @@ private Map<String, Object> buildPayload() {
payload.put("bcc", bcc);
}

if (replyTo != null) {
if (!replyTo.isEmpty()) {
payload.put("reply_to", replyTo);
}

Expand Down
42 changes: 41 additions & 1 deletion src/test/java/co/lettermint/EmailEndpointTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void testEmailWithAllOptions() throws Exception {
assertTrue(body.contains("\"to\":[\"recipient1@example.com\",\"recipient2@example.com\"]"));
assertTrue(body.contains("\"cc\":[\"cc@example.com\"]"));
assertTrue(body.contains("\"bcc\":[\"bcc@example.com\"]"));
assertTrue(body.contains("\"reply_to\":\"reply@example.com\""));
assertTrue(body.contains("\"reply_to\":[\"reply@example.com\"]"));
assertTrue(body.contains("\"subject\":\"Welcome!\""));
assertTrue(body.contains("\"html\":\"<p>Hello <b>World</b></p>\""));
assertTrue(body.contains("\"text\":\"Hello World\""));
Expand Down Expand Up @@ -179,6 +179,46 @@ void testSingleHeaderMethod() throws Exception {
assertTrue(body.contains("\"X-Second\":\"value2\""));
}

@Test
void testReplyToSingleString() throws Exception {
mockWebServer.enqueue(new MockResponse()
.setBody("{\"message_id\": \"msg_123\", \"status\": \"queued\"}")
.setHeader("Content-Type", "application/json"));

lettermint.email()
.from("sender@example.com")
.to("recipient@example.com")
.subject("Test")
.text("Test")
.replyTo("reply@example.com")
.send();

RecordedRequest request = mockWebServer.takeRequest();
String body = request.getBody().readUtf8();

assertTrue(body.contains("\"reply_to\":[\"reply@example.com\"]"));
}

@Test
void testReplyToMultipleAddresses() throws Exception {
mockWebServer.enqueue(new MockResponse()
.setBody("{\"message_id\": \"msg_123\", \"status\": \"queued\"}")
.setHeader("Content-Type", "application/json"));

lettermint.email()
.from("sender@example.com")
.to("recipient@example.com")
.subject("Test")
.text("Test")
.replyTo("reply1@example.com", "reply2@example.com")
.send();

RecordedRequest request = mockWebServer.takeRequest();
String body = request.getBody().readUtf8();

assertTrue(body.contains("\"reply_to\":[\"reply1@example.com\",\"reply2@example.com\"]"));
}

@Test
void testSingleMetadataMethod() throws Exception {
mockWebServer.enqueue(new MockResponse()
Expand Down