Class HttpMailDispatcher

java.lang.Object
com.onec.mail.dispatch.HttpMailDispatcher
All Implemented Interfaces:
MailDispatcher

public class HttpMailDispatcher extends Object implements 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 Classes
    Modifier and Type
    Class
    Description
    static final class 
    Exposed to templates as json; renders a value as a quoted, escaped JSON literal.
  • Constructor Summary

    Constructors
    Constructor
    Description
    HttpMailDispatcher(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 Type
    Method
    Description
    void
    Synchronously deliver a message to the provider.
    Stable provider id, e.g.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public String name()
      Description copied from interface: MailDispatcher
      Stable provider id, e.g. "smtp", "sendgrid", "ses".
      Specified by:
      name in interface MailDispatcher
    • dispatch

      public void dispatch(MailMessage message)
      Description copied from interface: MailDispatcher
      Synchronously deliver a message to the provider. Throws MailDeliveryException on failure.
      Specified by:
      dispatch in interface MailDispatcher