Skip to content

Commit ba4d166

Browse files
authored
Merge pull request #1 from davidangb/replyToList
Reply to list
2 parents 352d353 + 834fe09 commit ba4d166

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

examples/helpers/mail/Example.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,22 @@ public static Mail buildHelloEmail() {
241241
return mail;
242242
}
243243

244+
// Multiple Reply-To addresses on a Mail
245+
public static Mail buildMultipleReplyToEmail() {
246+
Email from = new Email("from@example.com");
247+
String subject = "Hello World from the Twilio SendGrid Java Library";
248+
Email to = new Email("to@example.com");
249+
Content content = new Content("text/plain", "some text here");
250+
Mail mail = new Mail(from, subject, to, content);
251+
252+
Email replyTo1 = new Email("replyto1@example.com");
253+
Email replyTo2 = new Email("replyto2@example.com");
254+
mail.setReplyTo(Arrays.asList(replyTo1, replyTo2));
255+
256+
return mail;
257+
}
258+
259+
244260
public static void baselineExample() throws IOException {
245261
final Mail helloWorld = buildHelloEmail();
246262
send(helloWorld);
@@ -256,6 +272,11 @@ public static void dynamicTemplateExample() throws IOException {
256272
send(dynamicTemplate);
257273
}
258274

275+
public static void MultipleReplyToExample() throws IOException {
276+
final Mail multipleReplyTo = buildMultipleReplyToEmail();
277+
send(multipleReplyTo);
278+
}
279+
259280
private static void send(final Mail mail) throws IOException {
260281
final SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
261282
sg.addRequestHeader("X-Mock", "true");

src/main/java/com/sendgrid/helpers/mail/Mail.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ public class Mail {
117117
@JsonProperty("reply_to")
118118
public Email replyTo;
119119

120+
/** The email's list of reply to addresses. */
121+
@JsonProperty("reply_to_list")
122+
public List<Email> replyToList;
123+
120124
private static final ObjectMapper SORTED_MAPPER = new ObjectMapper();
121125

122126
static {
@@ -505,6 +509,33 @@ public void setReplyTo(Email replyTo) {
505509
this.replyTo = replyTo;
506510
}
507511

512+
/**
513+
* Get the email's list of reply to addresses.
514+
*
515+
* @return the list of reply to addresses.
516+
*/
517+
public List<Email> getReplyToList() {
518+
return replyToList;
519+
}
520+
521+
/**
522+
* Set the email's list of reply to addresses.
523+
*
524+
* @param replyToList the list of reply to addresses.
525+
*/
526+
public void setReplyToList(List<Email> replyToList) {
527+
this.replyToList = replyToList;
528+
}
529+
530+
/**
531+
* Appends to the email's list of reply to addresses.
532+
*
533+
* @param replyTo the address to append to the list of reply to addresses.
534+
*/
535+
public void addReplyTo(Email replyTo) {
536+
this.replyToList = addToList(replyTo, this.replyToList);
537+
}
538+
508539
/**
509540
* Create a string representation of the Mail object JSON.
510541
*

src/test/java/com/sendgrid/helpers/MailTest.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.junit.Test;
99

1010
import java.util.ArrayList;
11+
import java.util.Arrays;
12+
import java.util.Collections;
1113
import java.util.HashMap;
1214
import java.util.List;
1315
import java.util.Map;
@@ -264,7 +266,30 @@ public void testKitchenSink() throws IOException {
264266
replyTo.setEmail("test@example.com");
265267
mail.setReplyTo(replyTo);
266268

267-
Assert.assertEquals(mail.build(), "{\"from\":{\"name\":\"Example User\",\"email\":\"test@example.com\"},\"subject\":\"Hello World from the SendGrid Java Library\",\"personalizations\":[{\"to\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"cc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"subject\":\"Hello World from the Personalized SendGrid Java Library\",\"headers\":{\"X-Mock\":\"true\",\"X-Test\":\"test\"},\"substitutions\":{\"%city%\":\"Denver\",\"%name%\":\"Example User\"},\"custom_args\":{\"type\":\"marketing\",\"user_id\":\"343\"},\"send_at\":1443636843},{\"to\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"from\":{\"name\":\"Example Sender\",\"email\":\"sender@example.com\"},\"cc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"subject\":\"Hello World from the Personalized SendGrid Java Library\",\"headers\":{\"X-Mock\":\"true\",\"X-Test\":\"test\"},\"substitutions\":{\"%city%\":\"Denver\",\"%name%\":\"Example User\"},\"custom_args\":{\"type\":\"marketing\",\"user_id\":\"343\"},\"send_at\":1443636843},{\"to\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"from\":{\"name\":\"Example Sender2\",\"email\":\"sender2@example.com\"},\"cc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"subject\":\"Hello World from the Personalized SendGrid Java Library\",\"headers\":{\"X-Mock\":\"true\",\"X-Test\":\"test\"},\"custom_args\":{\"type\":\"marketing\",\"user_id\":\"343\"},\"dynamic_template_data\":{\"city\":\"Denver\",\"items\":[{\"price\":\"$ 59.95\",\"text\":\"New Line Sneakers\"},{\"text\":\"Old Line Sneakers\"}],\"name\":\"Example User\"},\"send_at\":1443636843}],\"content\":[{\"type\":\"text/plain\",\"value\":\"some text here\"},{\"type\":\"text/html\",\"value\":\"<html><body>some text here</body></html>\"}],\"attachments\":[{\"content\":\"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12\",\"type\":\"application/pdf\",\"filename\":\"balance_001.pdf\",\"disposition\":\"attachment\",\"content_id\":\"Balance Sheet\"},{\"content\":\"BwdW\",\"type\":\"image/png\",\"filename\":\"banner.png\",\"disposition\":\"inline\",\"content_id\":\"Banner\"}],\"template_id\":\"13b8f94f-bcae-4ec6-b752-70d6cb59f932\",\"sections\":{\"%section1%\":\"Substitution Text for Section 1\",\"%section2%\":\"Substitution Text for Section 2\"},\"headers\":{\"X-Test1\":\"1\",\"X-Test2\":\"2\"},\"categories\":[\"May\",\"2016\"],\"custom_args\":{\"campaign\":\"welcome\",\"weekday\":\"morning\"},\"send_at\":1443636842,\"asm\":{\"group_id\":99,\"groups_to_display\":[4,5,6,7,8]},\"ip_pool_name\":\"23\",\"mail_settings\":{\"bcc\":{\"enable\":true,\"email\":\"test@example.com\"},\"bypass_list_management\":{\"enable\":true},\"bypass_spam_management\":{\"enable\":true},\"bypass_bounce_management\":{\"enable\":true},\"bypass_unsubscribe_management\":{\"enable\":true},\"footer\":{\"enable\":true,\"text\":\"Footer Text\",\"html\":\"<html><body>Footer Text</body></html>\"},\"sandbox_mode\":{\"enable\":true},\"spam_check\":{\"enable\":true,\"threshold\":1,\"post_to_url\":\"https://spamcatcher.sendgrid.com\"}},\"tracking_settings\":{\"click_tracking\":{\"enable\":true,\"enable_text\":false},\"open_tracking\":{\"enable\":true,\"substitution_tag\":\"Optional tag to replace with the open image in the body of the message\"},\"subscription_tracking\":{\"enable\":true,\"text\":\"text to insert into the text/plain portion of the message\",\"html\":\"<html><body>html to insert into the text/html portion of the message</body></html>\",\"substitution_tag\":\"Optional tag to replace with the open image in the body of the message\"},\"ganalytics\":{\"enable\":true,\"utm_source\":\"some source\",\"utm_term\":\"some term\",\"utm_content\":\"some content\",\"utm_campaign\":\"some name\",\"utm_medium\":\"some medium\"}},\"reply_to\":{\"name\":\"Example User\",\"email\":\"test@example.com\"}}");
269+
Email replyToEmail1 = new Email();
270+
replyToEmail1.setName("Reply To List 1");
271+
replyToEmail1.setEmail("replyToList1@example.com");
272+
Email replyToEmail2 = new Email();
273+
replyToEmail2.setName("Reply To List 2");
274+
replyToEmail2.setEmail("replyToList2@example.com");
275+
List<Email> replyToList = new ArrayList<>();
276+
replyToList.add(replyToEmail1);
277+
replyToList.add(replyToEmail2);
278+
mail.setReplyToList(replyToList);
279+
280+
Assert.assertEquals(mail.build(), "{\"from\":{\"name\":\"Example User\",\"email\":\"test@example.com\"},\"subject\":\"Hello World from the SendGrid Java Library\",\"personalizations\":[{\"to\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"cc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"subject\":\"Hello World from the Personalized SendGrid Java Library\",\"headers\":{\"X-Mock\":\"true\",\"X-Test\":\"test\"},\"substitutions\":{\"%city%\":\"Denver\",\"%name%\":\"Example User\"},\"custom_args\":{\"type\":\"marketing\",\"user_id\":\"343\"},\"send_at\":1443636843},{\"to\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"from\":{\"name\":\"Example Sender\",\"email\":\"sender@example.com\"},\"cc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"subject\":\"Hello World from the Personalized SendGrid Java Library\",\"headers\":{\"X-Mock\":\"true\",\"X-Test\":\"test\"},\"substitutions\":{\"%city%\":\"Denver\",\"%name%\":\"Example User\"},\"custom_args\":{\"type\":\"marketing\",\"user_id\":\"343\"},\"send_at\":1443636843},{\"to\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"from\":{\"name\":\"Example Sender2\",\"email\":\"sender2@example.com\"},\"cc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"subject\":\"Hello World from the Personalized SendGrid Java Library\",\"headers\":{\"X-Mock\":\"true\",\"X-Test\":\"test\"},\"custom_args\":{\"type\":\"marketing\",\"user_id\":\"343\"},\"dynamic_template_data\":{\"city\":\"Denver\",\"items\":[{\"price\":\"$ 59.95\",\"text\":\"New Line Sneakers\"},{\"text\":\"Old Line Sneakers\"}],\"name\":\"Example User\"},\"send_at\":1443636843}],\"content\":[{\"type\":\"text/plain\",\"value\":\"some text here\"},{\"type\":\"text/html\",\"value\":\"<html><body>some text here</body></html>\"}],\"attachments\":[{\"content\":\"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12\",\"type\":\"application/pdf\",\"filename\":\"balance_001.pdf\",\"disposition\":\"attachment\",\"content_id\":\"Balance Sheet\"},{\"content\":\"BwdW\",\"type\":\"image/png\",\"filename\":\"banner.png\",\"disposition\":\"inline\",\"content_id\":\"Banner\"}],\"template_id\":\"13b8f94f-bcae-4ec6-b752-70d6cb59f932\",\"sections\":{\"%section1%\":\"Substitution Text for Section 1\",\"%section2%\":\"Substitution Text for Section 2\"},\"headers\":{\"X-Test1\":\"1\",\"X-Test2\":\"2\"},\"categories\":[\"May\",\"2016\"],\"custom_args\":{\"campaign\":\"welcome\",\"weekday\":\"morning\"},\"send_at\":1443636842,\"asm\":{\"group_id\":99,\"groups_to_display\":[4,5,6,7,8]},\"ip_pool_name\":\"23\",\"mail_settings\":{\"bcc\":{\"enable\":true,\"email\":\"test@example.com\"},\"bypass_list_management\":{\"enable\":true},\"bypass_spam_management\":{\"enable\":true},\"bypass_bounce_management\":{\"enable\":true},\"bypass_unsubscribe_management\":{\"enable\":true},\"footer\":{\"enable\":true,\"text\":\"Footer Text\",\"html\":\"<html><body>Footer Text</body></html>\"},\"sandbox_mode\":{\"enable\":true},\"spam_check\":{\"enable\":true,\"threshold\":1,\"post_to_url\":\"https://spamcatcher.sendgrid.com\"}},\"tracking_settings\":{\"click_tracking\":{\"enable\":true,\"enable_text\":false},\"open_tracking\":{\"enable\":true,\"substitution_tag\":\"Optional tag to replace with the open image in the body of the message\"},\"subscription_tracking\":{\"enable\":true,\"text\":\"text to insert into the text/plain portion of the message\",\"html\":\"<html><body>html to insert into the text/html portion of the message</body></html>\",\"substitution_tag\":\"Optional tag to replace with the open image in the body of the message\"},\"ganalytics\":{\"enable\":true,\"utm_source\":\"some source\",\"utm_term\":\"some term\",\"utm_content\":\"some content\",\"utm_campaign\":\"some name\",\"utm_medium\":\"some medium\"}},\"reply_to\":{\"name\":\"Example User\",\"email\":\"test@example.com\"},\"reply_to_list\":[{\"name\":\"Reply To List 1\",\"email\":\"replyToList1@example.com\"},{\"name\":\"Reply To List 2\",\"email\":\"replyToList2@example.com\"}]}");
281+
}
282+
283+
@Test
284+
public void addReplyToShouldAppend() {
285+
Mail mail = new Mail();
286+
Email replyTo1 = new Email("test1@example.com", "Test User1");
287+
Email replyTo2 = new Email("test2@example.com", "Test User2");
288+
mail.addReplyTo(replyTo1);
289+
Assert.assertEquals(Collections.singletonList(replyTo1), mail.getReplyToList());
290+
mail.addReplyTo(replyTo2);
291+
Assert.assertEquals(Arrays.asList(replyTo1, replyTo2), mail.getReplyToList());
292+
268293
}
269294

270295
@Test

0 commit comments

Comments
 (0)