Skip to content

Commit

Permalink
Support toggling internal mail handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wolveix committed Sep 18, 2024
1 parent 633a4df commit 54dba82
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
27 changes: 27 additions & 0 deletions email.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,33 @@ func (c *UserContext) UpdateEmailAccount(emailAccount EmailAccount) error {
return nil
}

// UseInternalMailHandler tells the server to use the local mail handler for the given domain. If this is enabled, other
// domains on the server that email this domain will use the server's local mail handler to deliver the email, rather
// than looking up the domain's MX records. This is fine if your email is being hosted on the same server, but not
// otherwise.
func (c *UserContext) UseInternalMailHandler(domain string, enable bool) error {
var response apiGenericResponse

body := url.Values{}
body.Set("domain", domain)

if enable {
body.Set("internal", "yes")
} else {
body.Set("internal", "no")
}

if _, err := c.makeRequestOld(http.MethodPost, "API_DNS_MX?action=internal", body, &response); err != nil {
return err
}

if response.Success != "Option Saved" {
return fmt.Errorf("failed to set internal mail handler for %v: %v", domain, response.Result)
}

return nil
}

// VerifyEmailAccount (user) accepts the full email address as well as the password for the account. If the credentials aren't correct, an error will be returned.
func (c *UserContext) VerifyEmailAccount(address string, password string) error {
var response apiGenericResponse
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ go 1.22
require (
github.com/goccy/go-json v0.10.3
github.com/google/go-querystring v1.1.0
github.com/spf13/cast v1.6.0
golang.org/x/text v0.15.0
github.com/spf13/cast v1.7.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

0 comments on commit 54dba82

Please sign in to comment.