Package net.bugreaper.modules.email
Class Email
java.lang.Object
net.bugreaper.modules.email.Email
- All Implemented Interfaces:
EmailInt
Email helper that provides a common API for sending emails via SMTP using Jakarta Mail.
Supports:
- Simple email sending
- Fluent builder API for advanced emails
- Attachments
- Custom headers (tags)
It is recommended to use a single instance:
Email email = Email.getInstance();
Typical usage:
email.build("Subject", "Body")
.setFrom("your_email@gmail.com")
.addTo("my_email@gmail.com")
.addAttach("file.txt", "tmp/file.txt")
.addTags("qa")
.send();
- Since:
- 1.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classFluent builder for constructing complex emails. -
Constructor Summary
ConstructorsConstructorDescriptionEmail()Constructs a Email client using YAML configuration.Creates an Email helper configured for unauthenticated SMTP.Creates an EmailMailpit helper configured for authenticated SMTP. -
Method Summary
-
Constructor Details
-
Email
Creates an EmailMailpit helper configured for authenticated SMTP.- Parameters:
host- SMTP server host (e.g. smtp.gmail.com)port- SMTP port (e.g. 587 for TLS)username- SMTP usernamepassword- SMTP password or app password
-
Email
Creates an Email helper configured for unauthenticated SMTP.- Parameters:
host- SMTP server host (e.g. smtp.gmail.com)port- SMTP port (e.g. 587 for TLS)
-
Email
public Email()Constructs a Email client using YAML configuration.Loads configuration values from a YAML file.
Default file:
bugreaper.ymlCustom file: using
-DbugreaperEnv=testloadsbugreaper-test.ymlmodules: email: host: localhost port: 1025 auth: true # (optional) username: 'user' # (optional) password: 'password123' # (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 ofEmail.This implementation is thread-safe using method-level synchronization.
- Returns:
- the shared instance of
Email - Throws:
IllegalArgumentException- if the configuration contains invalid values- See Also:
-
getConfigSummary
-
sendEmail
@Step("(EMAIL)[SEND] Simple email to: \'{to}\'") public void sendEmail(String from, String to, String subject, @Param(mode=HIDDEN) String body) Description copied from interface:EmailIntSends a simple plain-text email. -
build
Description copied from interface:EmailIntEntry point for fluent email builder.REQUIRED:
Email.EmailBuilder.addTo(String)andEmail.EmailBuilder.setFrom(String)Finalize send with
Email.EmailBuilder.send()
-