Files
meshcore-analyzer/internal/mailer/httpclient.go
T
CoderNemesisandCoderNemesis d9342bbebd (feat): UserManagement, Add Support for Postal Email Delivery Provider (#2154)
This PR extends email support to add another email delivery provider
called Postal for user management. It is a, open source, self hosted
email delivery and reputation management service.

It adds 2 new additional configuration settings to the
userManagement.mail object which are "postalBaseUrl" and "postalApiKey".
It also adds "postal" as a supported value for the "provider" setting.
All existing functionality including email delivery notification is
supported by Postal.

Included test cases to support the new functionality and all pipelines
pass.

---------

Co-authored-by: CoderNemesis <rfedor@comchan.net>
2026-10-11 11:28:20 +02:00

34 lines
818 B
Go

package mailer
import (
"io"
"net/http"
"time"
)
// newNoRedirectHTTPClient never follows redirects, so a provider's API key
// header cannot be forwarded to another host.
func newNoRedirectHTTPClient() *http.Client {
return &http.Client{
Timeout: 10 * time.Second,
CheckRedirect: func(*http.Request, []*http.Request) error {
return http.ErrUseLastResponse
},
}
}
// doLimited sends r and reads at most 256 KiB of the response. A nil client
// gets a fresh no-redirect one.
func doLimited(client *http.Client, r *http.Request) ([]byte, int, error) {
if client == nil {
client = newNoRedirectHTTPClient()
}
resp, err := client.Do(r)
if err != nil {
return nil, 0, err
}
defer resp.Body.Close()
data, err := io.ReadAll(io.LimitReader(resp.Body, 256<<10))
return data, resp.StatusCode, err
}