feat: support custom HTTP headers in custom HttpEmailProvider and hide unused fields (#3723)

This commit is contained in:
DacongDA
2025-04-13 23:52:04 +08:00
committed by GitHub
parent 019fd87b92
commit e3d5619b25
31 changed files with 363 additions and 14 deletions

View File

@ -24,14 +24,16 @@ import (
)
type HttpEmailProvider struct {
endpoint string
method string
endpoint string
method string
httpHeaders map[string]string
}
func NewHttpEmailProvider(endpoint string, method string) *HttpEmailProvider {
func NewHttpEmailProvider(endpoint string, method string, httpHeaders map[string]string) *HttpEmailProvider {
client := &HttpEmailProvider{
endpoint: endpoint,
method: method,
endpoint: endpoint,
method: method,
httpHeaders: httpHeaders,
}
return client
}
@ -39,7 +41,7 @@ func NewHttpEmailProvider(endpoint string, method string) *HttpEmailProvider {
func (c *HttpEmailProvider) Send(fromAddress string, fromName string, toAddress string, subject string, content string) error {
var req *http.Request
var err error
if c.method == "POST" {
if c.method == "POST" || c.method == "PUT" || c.method == "DELETE" {
formValues := url.Values{}
formValues.Set("fromName", fromName)
formValues.Set("toAddress", toAddress)
@ -67,6 +69,10 @@ func (c *HttpEmailProvider) Send(fromAddress string, fromName string, toAddress
return fmt.Errorf("HttpEmailProvider's Send() error, unsupported method: %s", c.method)
}
for k, v := range c.httpHeaders {
req.Header.Set(k, v)
}
httpClient := proxy.DefaultHttpClient
resp, err := httpClient.Do(req)
if err != nil {