An Epsilon Harmony client for Java applications.
- OkHttp - Http client for Epsilon mail services
- Jackson - JSON library for Java
- SLF4J - Simple Logging Facade
To build library use:
./mvnw package -DskipTests
Tests could be run by following command:
./mvnw test
HarmonyClient
should be shared. It performs best when you create only a single instance and reuse it for all of your calls. This is because each client holds its own connection pool and thread pools. Reusing connections and threads reduces latency and saves memory.
First you need to create a shared instance with default settings clientId, userName and passwords are mandatory to supply, others settings could be overridden, see HarmonyClient.Builder
API.
public final HarmonyClient client = new HarmonyClient.Builder()
.withClientId("<client_id>")
.withClientPass("<client_pass>")
.withUserName("<user_name>")
.withUserPass("<user_pass>")
.build();
Shutdown isn't necessary.
Prepare a request with at least one recipient with at least one mail attribute (according to Epsilon) every email should have at least one Recipient with at least one attribute.
SendMailRequest sendMailRequest = new SendMailRequest(
"<message_id>",
new SendMailRequest.Recipient("<[email protected]>",
new SendMailRequest.Attribute("<attr_name>", "<attr_value>")
));
//send email synchronously
try (SendMailResponse sendMailResponse = harmonyClient.sendMail(aolOrgId, sendMailRequest).get()) {
// process response
}
// or asynchronously
harmonyClient.sendMail(aolOrgId, sendMailRequest).handle((r, e) -> {
if (e != null) {
// deal with error
} else {
// process response
}
});
- Create configuration for HarmonyClient:
@Configuration
@ConfigurationProperties(prefix="harmony")
public class HarmonyClientConfig {
private String clientId;
private String clientPassword;
private String userName;
private String userPassword;
// getter and setters here
@Bean
public harmonyClient() {
return new HarmonyClient.Builder()
.withClientId(clientId)
.withClientPass(clientPassword)
.withUserName(userName)
.withUserPass(userPassword)
.build();
}
}
- Provide passwords in
application.properties
harmony.client-id="<client-id>"
harmony.client-password="<client-password>"
harmony.user-name="<user-name>"
harmony.user-password="<user-password>"
- Inject it into your service
@Autowired
private final HarmonyClient harmonyClient;
To generate eclipse
project files use:
./mvnw eclipse:eclipse
To generate idea
project files use:
./mvnw idea:idea
Or you can import the maven
project directly from your favorite IDE
.