if (StringUtils.isNotBlank(reasonNotPermitted)) {
return apiRequest.denyRequest(reasonNotPermitted);
}
String apiMessage = null;
AwsEmailConfig config = apiClient.getAwsEmailConfig();
Body body = new Body();
if (StringUtils.isBlank(action.getHtmlContent())) {
body.withText(new Content().withCharset("UTF-8").withData("-no message-"));
} else {
body.withHtml(new Content().withCharset("UTF-8").withData(action.getHtmlContent()));
}
SendEmailRequest sendEmailRequest = new SendEmailRequest();
sendEmailRequest.withSource(action.getFromAddress());
sendEmailRequest.withReturnPath(action.getFromAddress());
sendEmailRequest.withReplyToAddresses(action.getFromAddress());
if (StringUtils.isNotBlank(config.getRecipientOverride())) {
// This is NOT a "production" request.
sendEmailRequest.setDestination(new Destination().withToAddresses(config.getRecipientOverride()));
apiMessage = String.format("Request sent to recipient override, %s.", config.getRecipientOverride());
} else {
// This IS a "production" request.
sendEmailRequest.setDestination(new Destination().withToAddresses(action.getToAddress()));
}
Content subject = new Content().withCharset("UTF-8").withData(action.getEmailSubject());
sendEmailRequest.setMessage(new Message(subject, body));
AWSCredentials awsCredentials = new BasicAWSCredentials(config.getAccessKeyId(), config.getSecretKey());
new AmazonSimpleEmailServiceClient(awsCredentials).sendEmail(sendEmailRequest);
return apiRequest.processed(apiMessage);
}