Package com.mxraven.mail.notify


package com.mxraven.mail.notify
Consumes mxRaven client notification events over NATS JetStream.

When notifications are enabled for a listener (see the admin module's listener notification setting), mxRaven publishes every accepted message and every delivery attempt to that listener's durable JetStream consumer. This package consumes those events with the listener's ordinary API key:


 NotificationClient client = NotificationClient.connect(
         NotificationClientOptions.builder()
                 .username("mxr_tx_ab12cd34ef56")
                 .secret(System.getenv("MXRAVEN_SECRET"))
                 .listener(listenerId)
                 .build());

 client.consume(new NotificationCallbacks() {
     @Override
     public HandlerResult onAttempt(AttemptEvent event) {
         System.out.println(event.status());
         return HandlerResult.CONTINUE;
     }
 });
 

NotificationClient.consume(com.mxraven.mail.notify.NotificationHandler) acknowledges an event when its handler returns, redelivers it with exponential backoff when the handler throws, and stops when the handler returns HandlerResult.STOP. NotificationClient.events() is the lower-level iterator for callers that acknowledge each event themselves.

Fault events are described by FaultEvent: an MTA listener's routing script faulted and deferred the transaction, so there is no accepted event. They are sampled per script revision.

Accepted events are described by AcceptedMessage: the message summary and headers, the SMTP envelope, the routing-script decision, and raw-message access. An MTA listener's accepted event carries a RawEmail that AcceptedMessage.parse() downloads; a submission listener's event leaves it empty. Attempt events are described by AttemptEvent.

The consumer and its subject are managed by the control plane. Enable notifications with the administrative API before connecting; the consumer name defaults to notify-<listener>.