Skip to content

Commit

Permalink
Merge pull request #6 from intensiongmbh/apiExceptionMessage
Browse files Browse the repository at this point in the history
Throw EmailException with message from sendinblue.ApiException
  • Loading branch information
a-team-intension authored Apr 6, 2021
2 parents 517d7fa + a117a59 commit fe25346
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
environment:
KEYCLOAK_USER: admin
KEYCLOAK_PASSWORD: keycloak
SENDINBLUE_API_KEY: none
volumes:
- /etc/localtime:/etc/localtime:ro
- ./test/email-provider.cli:/opt/jboss/startup-scripts/email-provider.cli
- "./sendinblue-bundle/target/keycloak-sendinblue-bundle-KC-${KEYCLOAK_VERSION}-docker.ear:/opt/jboss/keycloak/standalone/deployments/keycloak-sendinblue.ear"
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

<properties>
<keycloak.version>12.0.4</keycloak.version>
<projectVersion>1.0.0</projectVersion>
<projectVersion>1.0.1</projectVersion>
<changelist>-SNAPSHOT</changelist>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public static SendinblueSender create()
* @param user recipient of the email
* @param templateId ID of the template to use for the mail
* @param params paramter to be replaced in the mail template
* @throws EmailException with message from Sendinblue's {@link ApiException} (for example:
* 'Unauthorized' when API key is invalid or
* 'Not Found' when template couldn't be found.
*/
public void postToSendinblue(UserModel user, long templateId, Map<String, String> params)
throws EmailException
Expand All @@ -48,10 +51,11 @@ public void postToSendinblue(UserModel user, long templateId, Map<String, String
.to(Arrays.asList(recipient));

try {
apiInstance.getSmtpTemplate(templateId);
apiInstance.sendTransacEmail(sendSmtpEmail);
} catch (ApiException e) {
LOGGER.errorf("[%s] Unable to send transactional mail for user '%s'", LogId.KCSIB0002, user.getEmail());
throw new EmailException("Failed to send mail with Sendinblue", e);
throw new EmailException(e.getMessage(), e);
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/email-provider.cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
embed-server --server-config=standalone-ha.xml --std-out=echo
/subsystem=keycloak-server/spi=emailSender/:add
/subsystem=keycloak-server/spi=emailSender/provider=sendinblue-email-provider/:add(enabled=true,properties={api-key => "${env.SENDINBLUE_API_KEY}"})
:reload
stop-embedded-server

0 comments on commit fe25346

Please sign in to comment.