Class MailpitClient

java.lang.Object
ch.martinelli.oss.testcontainers.mailpit.MailpitClient

public class MailpitClient extends Object
Client for interacting with the Mailpit REST API.

Provides methods to retrieve, inspect, and delete caught email messages.

See Also:
  • Constructor Details

    • MailpitClient

      public MailpitClient(String baseUrl)
  • Method Details

    • getAllMessages

      public List<Message> getAllMessages()
      Retrieves all messages from Mailpit.
      Returns:
      a list of all caught messages
      Throws:
      MailpitException - if an error occurs while fetching messages
    • getMessageCount

      public int getMessageCount()
      Returns the number of messages in Mailpit.
      Returns:
      the message count
      Throws:
      MailpitException - if an error occurs
    • getMessage

      public Message getMessage(String id)
      Retrieves a specific message by ID.
      Parameters:
      id - the message ID
      Returns:
      the message details
      Throws:
      MailpitException - if an error occurs or the message is not found
    • getMessageHtml

      public String getMessageHtml(String id)
      Retrieves the HTML body of a message.
      Parameters:
      id - the message ID
      Returns:
      the HTML body, or null if not available
      Throws:
      MailpitException - if an error occurs
    • getMessagePlain

      public String getMessagePlain(String id)
      Retrieves the plain text body of a message.
      Parameters:
      id - the message ID
      Returns:
      the plain text body, or null if not available
      Throws:
      MailpitException - if an error occurs
    • getMessageSource

      public String getMessageSource(String id)
      Retrieves the raw source of a message.
      Parameters:
      id - the message ID
      Returns:
      the raw message source
      Throws:
      MailpitException - if an error occurs
    • deleteAllMessages

      public void deleteAllMessages()
      Deletes all messages from Mailpit.
      Throws:
      MailpitException - if an error occurs
    • deleteMessages

      public void deleteMessages(List<String> ids)
      Deletes specific messages by their IDs.
      Parameters:
      ids - the message IDs to delete
      Throws:
      MailpitException - if an error occurs
    • deleteMessage

      public void deleteMessage(String id)
      Deletes a specific message.
      Parameters:
      id - the message ID to delete
      Throws:
      MailpitException - if an error occurs