@@ -26,7 +26,8 @@ public class EmailEndpoint extends Endpoint {
2626 private List <Attachment > attachments ;
2727 private String route ;
2828 private Map <String , Object > metadata ;
29- private List <String > tags ;
29+ private String tag ;
30+ private Map <String , Object > settings ;
3031 private String idempotencyKey ;
3132
3233 public EmailEndpoint (LettermintClient client ) {
@@ -50,7 +51,8 @@ private void reset() {
5051 this .attachments = new ArrayList <>();
5152 this .route = null ;
5253 this .metadata = new LinkedHashMap <>();
53- this .tags = new ArrayList <>();
54+ this .tag = null ;
55+ this .settings = null ;
5456 this .idempotencyKey = null ;
5557 }
5658
@@ -196,10 +198,18 @@ public EmailEndpoint metadata(String key, Object value) {
196198 }
197199
198200 /**
199- * Add tags to the email.
201+ * Set the email tag .
200202 */
201- public EmailEndpoint tag (String ... tags ) {
202- this .tags .addAll (Arrays .asList (tags ));
203+ public EmailEndpoint tag (String tag ) {
204+ this .tag = tag ;
205+ return this ;
206+ }
207+
208+ /**
209+ * Set per-email settings that override the selected route.
210+ */
211+ public EmailEndpoint settings (Map <String , Object > settings ) {
212+ this .settings = new LinkedHashMap <>(settings );
203213 return this ;
204214 }
205215
@@ -231,7 +241,17 @@ public SendEmailResponse send() {
231241 }
232242
233243 public List <SendMailResponse > sendBatch (List <SendMailRequest > payloads ) {
234- return client .post ("/send/batch" , payloads , new TypeReference <List <SendMailResponse >>() {});
244+ Map <String , String > requestHeaders = null ;
245+
246+ if (idempotencyKey != null && !idempotencyKey .isEmpty ()) {
247+ requestHeaders = Collections .singletonMap ("Idempotency-Key" , idempotencyKey );
248+ }
249+
250+ try {
251+ return client .post ("/send/batch" , payloads , new TypeReference <List <SendMailResponse >>() {}, requestHeaders );
252+ } finally {
253+ reset ();
254+ }
235255 }
236256
237257 public String ping () {
@@ -289,8 +309,12 @@ private Map<String, Object> buildPayload() {
289309 payload .put ("metadata" , metadata );
290310 }
291311
292- if (!tags .isEmpty ()) {
293- payload .put ("tags" , tags );
312+ if (tag != null ) {
313+ payload .put ("tag" , tag );
314+ }
315+
316+ if (settings != null ) {
317+ payload .put ("settings" , settings );
294318 }
295319
296320 return payload ;
0 commit comments