Package com.onec.mail.dispatch
Class HttpMailDispatcher
java.lang.Object
com.onec.mail.dispatch.HttpMailDispatcher
- All Implemented Interfaces:
MailDispatcher
Universal provider adapter (
provider=http). POSTs a rendered, provider-specific JSON body
to any mail API's REST endpoint, so a new provider can be onboarded with config only — no new code.
The JSON payload is produced by the Thymeleaf template at onec.mail.http.body-template
(TEXT mode). The MailMessage is exposed as msg, and json.str(x) yields a
correctly-escaped, quoted JSON string. Example fragment for a SendGrid-style API:
{
"from": { "email": [(${json.str(msg.from)})] },
"subject": [(${json.str(msg.subject)})],
"content": [ { "type": "text/html", "value": [(${json.str(msg.html)})] } ]
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classExposed to templates asjson; renders a value as a quoted, escaped JSON literal. -
Constructor Summary
ConstructorsConstructorDescriptionHttpMailDispatcher(org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.core.io.ResourceLoader resourceLoader, com.fasterxml.jackson.databind.ObjectMapper objectMapper, MailProperties properties) -
Method Summary
Modifier and TypeMethodDescriptionvoiddispatch(MailMessage message) Synchronously deliver a message to the provider.name()Stable provider id, e.g.
-
Constructor Details
-
HttpMailDispatcher
public HttpMailDispatcher(org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.core.io.ResourceLoader resourceLoader, com.fasterxml.jackson.databind.ObjectMapper objectMapper, MailProperties properties)
-
-
Method Details
-
name
Description copied from interface:MailDispatcherStable provider id, e.g. "smtp", "sendgrid", "ses".- Specified by:
namein interfaceMailDispatcher
-
dispatch
Description copied from interface:MailDispatcherSynchronously deliver a message to the provider. ThrowsMailDeliveryExceptionon failure.- Specified by:
dispatchin interfaceMailDispatcher
-