Class EmailMailpit
- All Implemented Interfaces:
MailPitInterface
Class contains methods for interacting with Mailpit via its API without authentication. It provides simple wrappers around the REST module.
It is recommended to use a single instance:
EmailMailpit mailpit = EmailMailpit.getInstance();
- Since:
- 1.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a EmailMailpit client using YAML configuration.EmailMailpit(String url, int port) Creates an EmailMailpit helper with the specified connection settings. -
Method Summary
Modifier and TypeMethodDescriptionvoidDeletes all messages from all mailboxes.voidcleanMailbox(String mailbox) Deletes all messages from the mailbox.intReturns the number of messages in all mailboxes.Returns and logs (at INFO level) a human-readable summary of all resolved configuration values.intgetEmailsCountInMailbox(String mailbox) Returns the number of messages in the mailbox.static EmailMailpitReturns the instance ofEmailMailpitwith config builderEmailMailpit().getLatestEmailInMailbox(String mailbox) Returns the latest message from the mailbox in Mailpit format.voidseeAllEmailsCountExactly(int expectedCount) Asserts that the number of messages in all mailboxes equals the expected count.voidseeEmailsInMailboxCountExactly(String mailbox, int expectedCount) Asserts that the number of messages in specific mailbox equals the expected count.voidseeMailboxIsEmpty(String mailbox) Asserts that the mailbox is empty.voidseeMailboxIsNotEmpty(String mailbox) Asserts that the mailbox is not empty.setAwaitMs(int awaitMs) Configures the global await timeout for assertions that use await.voidsetChaosAuthentication(int code) Configures an authentication error in the Mailpit server for subsequent email sends.voidsetChaosRecipient(int code) Configures a recipient error in the Mailpit server for subsequent email sends.voidsetChaosSender(int code) Configures a sender error in the Mailpit server for subsequent email sends.voidDisables predefined chaos errors in the Mailpit server.
-
Constructor Details
-
EmailMailpit
Creates an EmailMailpit helper with the specified connection settings.- Parameters:
url- host of Mailpit"http://your-mailpit-host"port- port of Mailpit
-
EmailMailpit
public EmailMailpit()Constructs a EmailMailpit client using YAML configuration.Loads configuration values from a YAML file.
Default file:
bugreaper.ymlCustom file: using
-DbugreaperEnv=testloadsbugreaper-test.ymlmodules: mailpit: url: http://localhost port: 8025 await: 600 # (optional)Missing required keys will result in configuration errors. Missing optional keys will fall back to predefined defaults.
- Throws:
IllegalArgumentException- if the configuration contains invalid values
-
-
Method Details
-
getInstance
Returns the instance ofEmailMailpitwith config builderEmailMailpit().This implementation is thread-safe using method-level synchronization.
- Returns:
- the shared instance of
EmailMailpit - Throws:
IllegalArgumentException- if the configuration contains invalid values- See Also:
-
setAwaitMs
Description copied from interface:MailPitInterfaceConfigures the global await timeout for assertions that use await.- Specified by:
setAwaitMsin interfaceMailPitInterface- Parameters:
awaitMs- await timeout in milliseconds- Returns:
- this instance for method chaining
-
getConfigSummary
Description copied from interface:MailPitInterfaceReturns and logs (at INFO level) a human-readable summary of all resolved configuration values.The summary includes values loaded from the YAML configuration file as well as any fields overridden programmatically after construction. Optional fields that were not present in the configuration and resolved via default values may also be included.
- Specified by:
getConfigSummaryin interfaceMailPitInterface- Returns:
- String with summary
-
cleanAllMailboxes
@Step("(Email-mp) Clean all mailboxes") public void cleanAllMailboxes()Description copied from interface:MailPitInterfaceDeletes all messages from all mailboxes.- Specified by:
cleanAllMailboxesin interfaceMailPitInterface
-
cleanMailbox
Description copied from interface:MailPitInterfaceDeletes all messages from the mailbox.- Specified by:
cleanMailboxin interfaceMailPitInterface- Parameters:
mailbox- mailbox address
-
getLatestEmailInMailbox
@Step("(Email-mp) Get latest email from mailbox: \'{mailbox}\'") public AssertableMailpitResponse getLatestEmailInMailbox(String mailbox) Description copied from interface:MailPitInterfaceReturns the latest message from the mailbox in Mailpit format.- Specified by:
getLatestEmailInMailboxin interfaceMailPitInterface- Parameters:
mailbox- mailbox address- Returns:
AssertableMailpitResponseUsage Example:
mailpit.getLatestEmailInMailbox("my_email@gmail.com") .seeEmailContainsFrom("sender@gmail.com") .seeEmailAttachmentsCountExactly(2);can be provided multiple asserts
-
getAllEmailsCount
@Step("(Email-mp) Get all emails count") public int getAllEmailsCount()Description copied from interface:MailPitInterfaceReturns the number of messages in all mailboxes.- Specified by:
getAllEmailsCountin interfaceMailPitInterface- Returns:
- number of messages in all mailboxes
-
getEmailsCountInMailbox
@Step("(Email-MP) Get email count in mailbox \'{mailbox}\'") public int getEmailsCountInMailbox(String mailbox) Description copied from interface:MailPitInterfaceReturns the number of messages in the mailbox.- Specified by:
getEmailsCountInMailboxin interfaceMailPitInterface- Parameters:
mailbox- mailbox address- Returns:
- number of messages in the mailbox
-
unsetChaos
@Step("(Email-mp) Unset CHAOS") public void unsetChaos()Description copied from interface:MailPitInterfaceDisables predefined chaos errors in the Mailpit server.Works only when
MP_ENABLE_CHAOS=true.- Specified by:
unsetChaosin interfaceMailPitInterface
-
setChaosAuthentication
public void setChaosAuthentication(int code) Description copied from interface:MailPitInterfaceConfigures an authentication error in the Mailpit server for subsequent email sends.Works only when
MP_ENABLE_CHAOS=trueandMP_SMTP_AUTH=true.- Specified by:
setChaosAuthenticationin interfaceMailPitInterface- Parameters:
code- error code between 400 and 599
-
setChaosRecipient
public void setChaosRecipient(int code) Description copied from interface:MailPitInterfaceConfigures a recipient error in the Mailpit server for subsequent email sends.Works only when
MP_ENABLE_CHAOS=true.- Specified by:
setChaosRecipientin interfaceMailPitInterface- Parameters:
code- error code between 400 and 599
-
setChaosSender
public void setChaosSender(int code) Description copied from interface:MailPitInterfaceConfigures a sender error in the Mailpit server for subsequent email sends.Works only when
MP_ENABLE_CHAOS=true.- Specified by:
setChaosSenderin interfaceMailPitInterface- Parameters:
code- error code between 400 and 599
-
seeAllEmailsCountExactly
@Step("(Email-mp)[ASSERT] All mailboxes have exactly <{expectedCount}> emails") public void seeAllEmailsCountExactly(int expectedCount) Description copied from interface:MailPitInterfaceAsserts that the number of messages in all mailboxes equals the expected count.Uses await.
- Specified by:
seeAllEmailsCountExactlyin interfaceMailPitInterface- Parameters:
expectedCount- expected number of messages
-
seeEmailsInMailboxCountExactly
@Step("(Email-mp)[ASSERT] Mailbox: \'{mailbox}\' has exactly <{expectedCount}> emails") public void seeEmailsInMailboxCountExactly(String mailbox, int expectedCount) Description copied from interface:MailPitInterfaceAsserts that the number of messages in specific mailbox equals the expected count.Uses await.
- Specified by:
seeEmailsInMailboxCountExactlyin interfaceMailPitInterface- Parameters:
mailbox- mailbox addressexpectedCount- expected number of messages
-
seeMailboxIsEmpty
@Step("(Email-mp)[ASSERT] Mailbox: \'{mailbox}\' is empty") public void seeMailboxIsEmpty(String mailbox) Description copied from interface:MailPitInterfaceAsserts that the mailbox is empty.Uses await.
- Specified by:
seeMailboxIsEmptyin interfaceMailPitInterface- Parameters:
mailbox- mailbox address
-
seeMailboxIsNotEmpty
@Step("(Email-mp)[ASSERT] Mailbox: \'{mailbox}\' is not empty") public void seeMailboxIsNotEmpty(String mailbox) Description copied from interface:MailPitInterfaceAsserts that the mailbox is not empty.Uses await.
- Specified by:
seeMailboxIsNotEmptyin interfaceMailPitInterface- Parameters:
mailbox- mailbox address
-