pub struct WebhookClient { /* private fields */ }Expand description
A client responsible for sending EmailPayload data to a configured webhook URL.
Encapsulates the hyper HTTP client setup with rustls for HTTPS support.
Implementations§
Source§impl WebhookClient
impl WebhookClient
Sourcepub fn new(config: Config) -> Self
pub fn new(config: Config) -> Self
Creates a new WebhookClient.
Initializes an HTTPS client using hyper-rustls with native system certificates.
Constructs a User-Agent string based on the crate’s name and version from Cargo.toml.
§Arguments
config- The application configuration, used to get the webhook URL.
§Panics
Panics if loading the system’s native root TLS certificates fails. This is considered a fatal error during startup.
Sourcepub async fn forward_email(&self, email: EmailPayload) -> Result<()>
pub async fn forward_email(&self, email: EmailPayload) -> Result<()>
Sends the given EmailPayload to the configured webhook URL.
Serializes the payload to JSON and sends it as an HTTPS POST request. Logs the outcome (success or failure status code) of the request.
Note: A non-successful HTTP status code from the webhook endpoint (e.g., 4xx, 5xx)
is logged as an error but does not cause this function to return an Err.
The email is considered successfully processed by MailLaser once the webhook
request is attempted.
§Arguments
email- TheEmailPayloadto send.
§Errors
Returns an Err if:
- Serialization of the
EmailPayloadto JSON fails. - Building the HTTP request fails.
- The HTTP request itself fails (e.g., network error, DNS resolution failure).