Skip to content

Commit

Permalink
CAMEL-21608: (aws2-ses) Support message tags
Browse files Browse the repository at this point in the history
Enhance to add support for message tags to the aws2-ses component. Tags
are useful for providing user-defined metadata that will appear in email
tracking events related to the sent email.
  • Loading branch information
dylanpiergies committed Jan 10, 2025
1 parent a2eff0e commit 9366d2c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@
"CamelAwsSesTo": { "index": 5, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "List of comma separated destination email address.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#TO" },
"CamelAwsSesCc": { "index": 6, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "List of comma separated destination carbon copy (cc) email address.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#CC" },
"CamelAwsSesBcc": { "index": 7, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "List of comma separated destination blind carbon copy (bcc) email address.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#BCC" },
"CamelAwsSesHtmlEmail": { "index": 8, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "Boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The flag to show if email content is HTML.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#HTML_EMAIL" },
"CamelAwsSesConfigurationSet": { "index": 9, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "TThe configuration set to send.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#CONFIGURATION_SET" }
"CamelAwsSesTags": { "index": 8, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "Map<String, String>", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "A collection of name\/value pairs to apply when sending the email. Tags are user-defined properties that are included in published email sending events.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#TAGS" },
"CamelAwsSesHtmlEmail": { "index": 9, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "Boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The flag to show if email content is HTML.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#HTML_EMAIL" },
"CamelAwsSesConfigurationSet": { "index": 10, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "TThe configuration set to send.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#CONFIGURATION_SET" }
},
"properties": {
"from": { "index": 0, "kind": "path", "displayName": "From", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.ses.Ses2Configuration", "configurationField": "configuration", "description": "The sender's email address." },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@
"CamelAwsSesTo": { "index": 5, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "List of comma separated destination email address.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#TO" },
"CamelAwsSesCc": { "index": 6, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "List of comma separated destination carbon copy (cc) email address.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#CC" },
"CamelAwsSesBcc": { "index": 7, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "List of comma separated destination blind carbon copy (bcc) email address.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#BCC" },
"CamelAwsSesHtmlEmail": { "index": 8, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "Boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The flag to show if email content is HTML.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#HTML_EMAIL" },
"CamelAwsSesConfigurationSet": { "index": 9, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "TThe configuration set to send.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#CONFIGURATION_SET" }
"CamelAwsSesTags": { "index": 8, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "Map<String, String>", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "A collection of name\/value pairs to apply when sending the email. Tags are user-defined properties that are included in published email sending events.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#TAGS" },
"CamelAwsSesHtmlEmail": { "index": 9, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "Boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The flag to show if email content is HTML.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#HTML_EMAIL" },
"CamelAwsSesConfigurationSet": { "index": 10, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "TThe configuration set to send.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#CONFIGURATION_SET" }
},
"properties": {
"from": { "index": 0, "kind": "path", "displayName": "From", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.ses.Ses2Configuration", "configurationField": "configuration", "description": "The sender's email address." },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public interface Ses2Constants {
String CC = "CamelAwsSesCc";
@Metadata(description = "List of comma separated destination blind carbon copy (bcc) email address.", javaType = "String")
String BCC = "CamelAwsSesBcc";
@Metadata(description = "A collection of name/value pairs to apply when sending the email. Tags are user-defined properties that are included in published email sending events.",
javaType = "Map<String, String>")
String TAGS = "CamelAwsSesTags";
@Metadata(description = "The flag to show if email content is HTML.", javaType = "Boolean")
String HTML_EMAIL = "CamelAwsSesHtmlEmail";
@Metadata(description = "TThe configuration set to send.", javaType = "String")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import org.apache.camel.Endpoint;
Expand All @@ -39,6 +40,7 @@
import software.amazon.awssdk.services.ses.model.Body;
import software.amazon.awssdk.services.ses.model.Content;
import software.amazon.awssdk.services.ses.model.Destination;
import software.amazon.awssdk.services.ses.model.MessageTag;
import software.amazon.awssdk.services.ses.model.SendEmailRequest;
import software.amazon.awssdk.services.ses.model.SendEmailResponse;
import software.amazon.awssdk.services.ses.model.SendRawEmailRequest;
Expand Down Expand Up @@ -86,6 +88,7 @@ private SendEmailRequest createMailRequest(Exchange exchange) {
request.returnPath(determineReturnPath(exchange));
request.replyToAddresses(determineReplyToAddresses(exchange));
request.message(createMessage(exchange));
request.tags(determineTags(exchange));
request.configurationSetName(determineConfigurationSet(exchange));
return request.build();
}
Expand All @@ -95,6 +98,7 @@ private SendRawEmailRequest createRawMailRequest(Exchange exchange) throws Excep
request.source(determineFrom(exchange));
request.destinations(determineRawTo(exchange));
request.rawMessage(createRawMessage(exchange));
request.tags(determineTags(exchange));
request.configurationSetName(determineConfigurationSet(exchange));
return request.build();
}
Expand Down Expand Up @@ -129,7 +133,6 @@ private software.amazon.awssdk.services.ses.model.RawMessage createRawMessage(Ex
return message.build();
}

@SuppressWarnings("unchecked")
private Collection<String> determineReplyToAddresses(Exchange exchange) {
String replyToAddresses = exchange.getIn().getHeader(Ses2Constants.REPLY_TO_ADDRESSES, String.class);
if (replyToAddresses == null) {
Expand Down Expand Up @@ -217,6 +220,20 @@ private String determineSubject(Exchange exchange) {
return subject;
}

@SuppressWarnings("unchecked")
private List<MessageTag> determineTags(Exchange exchange) {
Map<String, String> tagMap = exchange.getIn().getHeader(Ses2Constants.TAGS, Map.class);
if (tagMap == null || tagMap.isEmpty()) {
return null;
}
return tagMap.entrySet().stream()
.map(entry -> MessageTag.builder()
.name(entry.getKey())
.value(entry.getValue())
.build())
.toList();
}

private String determineConfigurationSet(Exchange exchange) {
String configuration = exchange.getIn().getHeader(Ses2Constants.CONFIGURATION_SET, String.class);
if (configuration == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@
*/
package org.apache.camel.component.aws2.ses;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.camel.BindToRegistry;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.ses.model.MessageTag;
import software.amazon.awssdk.services.ses.model.SendEmailRequest;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

public class SesComponentTest extends CamelTestSupport {

Expand Down Expand Up @@ -55,6 +57,8 @@ public void process(Exchange exchange) {
assertTrue(sendEmailRequest.replyToAddresses().contains("[email protected]"));
assertTrue(sendEmailRequest.replyToAddresses().contains("[email protected]"));
assertEquals("Subject", getSubject(sendEmailRequest));
assertFalse(sendEmailRequest.hasTags());
assertEquals(0, sendEmailRequest.tags().size());
assertEquals("This is my message text.", getBody(sendEmailRequest));
}

Expand All @@ -81,6 +85,7 @@ public void process(Exchange exchange) {
exchange.getIn().setHeader(Ses2Constants.REPLY_TO_ADDRESSES,
"[email protected], [email protected]");
exchange.getIn().setHeader(Ses2Constants.SUBJECT, "anotherSubject");
exchange.getIn().setHeader(Ses2Constants.TAGS, Map.of("tagName", "tagValue"));
}
});

Expand All @@ -97,6 +102,24 @@ public void process(Exchange exchange) {
assertTrue(sendEmailRequest.replyToAddresses().contains("[email protected]"));
assertEquals("anotherSubject", getSubject(sendEmailRequest));
assertEquals("This is my message text.", getBody(sendEmailRequest));
assertTrue(sendEmailRequest.hasTags());
assertEquals(List.of(MessageTag.builder().name("tagName").value("tagValue").build()), sendEmailRequest.tags());
}

@Test
public void sendMessageWithEmptyMessageTagsHeader() {
Exchange exchange = template.send("direct:start", new Processor() {
public void process(Exchange exchange) {
exchange.getIn().setBody("This is my message text.");
exchange.getIn().setHeader(Ses2Constants.TAGS, new HashMap<String, String>());
}
});

assertEquals("1", exchange.getIn().getHeader(Ses2Constants.MESSAGE_ID));

SendEmailRequest sendEmailRequest = sesClient.getSendEmailRequest();
assertFalse(sendEmailRequest.hasTags());
assertEquals(0, sendEmailRequest.tags().size());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,20 @@ public String awsSesCc() {
public String awsSesBcc() {
return "CamelAwsSesBcc";
}
/**
* A collection of name/value pairs to apply when sending the email.
* Tags are user-defined properties that are included in published email
* sending events.
*
* The option is a: {@code Map<String, String>} type.
*
* Group: producer
*
* @return the name of the header {@code AwsSesTags}.
*/
public String awsSesTags() {
return "CamelAwsSesTags";
}
/**
* The flag to show if email content is HTML.
*
Expand Down

0 comments on commit 9366d2c

Please sign in to comment.