git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/postmark/domains.go (about) 1 package postmark 2 3 import ( 4 "context" 5 "fmt" 6 "net/http" 7 "net/url" 8 ) 9 10 type Domain struct { 11 // Unique ID of the Domain. 12 ID int64 13 // Domain name 14 Name string 15 // DEPRECATED: See our [blog post](https://postmarkapp.com/blog/why-we-no-longer-ask-for-spf-records) to learn why this field was deprecated. 16 SPFVerified bool 17 // DKIM DNS text record has been setup correctly at your domain registrar or DNS host. 18 DKIMVerified bool 19 // DKIM is using a strength weaker than 1024 bit. If so, it’s possible to request a new DKIM using the RequestNewDKIM function below. 20 WeakDKIM bool 21 // The verification state of the Return-Path domain. Tells you if the Return-Path is actively being used or still needs further action to be used. 22 ReturnPathDomainVerified bool 23 } 24 25 type DomainsList struct { 26 TotalCount int 27 Domains []Domain 28 } 29 30 type DetailedDomain struct { 31 // Unique ID of the Domain. 32 ID int64 33 // Domain name 34 Name string 35 // DEPRECATED: See our [blog post](https://postmarkapp.com/blog/why-we-no-longer-ask-for-spf-records) to learn why this field was deprecated. 36 SPFVerified bool 37 // Host name used for the SPF configuration. 38 SPFHost string 39 // Value that must be setup at your domain registrar or DNS host in order for SPF to function correctly. 40 SPFTextValue string 41 // DKIM DNS text record has been setup correctly at your domain registrar or DNS host. 42 DKIMVerified bool 43 // DKIM is using a strength weaker than 1024 bit. If so, it’s possible to request a new DKIM using the RequestNewDKIM function below. 44 WeakDKIM bool 45 // DNS TXT host being used to validate messages sent in. 46 DKIMHost string 47 // DNS TXT value being used to validate messages sent in. 48 DKIMTextValue string 49 // If a DKIM rotation has been intiated or this DKIM is from a new Domain, this field will show the pending DKIM DNS TXT host which has yet to be setup and confirmed at your registrar or DNS host. 50 DKIMPendingHost string 51 // Similar to the DKIMPendingHost field, this will show the DNS TXT value waiting to be confirmed at your registrar or DNS host. 52 DKIMPendingTextValue string 53 // Once a new DKIM has been confirmed at your registrar or DNS host, Postmark will revoke the old DKIM host in preparation for removing it permantly from the system. 54 DKIMRevokedHost string 55 // Similar to DKIMRevokedHost, this field will show the DNS TXT value that will soon be removed from the Postmark system. 56 DKIMRevokedTextValue string 57 // Indicates whether you may safely delete the old DKIM DNS TXT records at your registrar or DNS host. The new DKIM is now safely in use. 58 SafeToRemoveRevokedKeyFromDNS bool 59 // While DKIM renewal or new DKIM operations are being conducted or setup, this field will indicate Pending. After all DNS TXT records are up to date and any pending renewal operations are finished, it will indicate Verified. 60 DKIMUpdateStatus string 61 // The custom Return-Path for this domain, please read our support page. 62 ReturnPathDomain string 63 // The verification state of the Return-Path domain. Tells you if the Return-Path is actively being used or still needs further action to be used. 64 ReturnPathDomainVerified bool 65 // The CNAME DNS record that Postmark expects to find at the ReturnPathDomain value. 66 ReturnPathDomainCNAMEValue string 67 } 68 69 type CreateDomainInput struct { 70 // Domain name 71 Name string 72 // A custom value for the Return-Path domain. It is an optional field, but it must be a subdomain of your From Email domain and must have a CNAME record that points to pm.mtasv.net. For more information about this field, please read our support page. 73 ReturnPathDomain string `json:",omitempty"` 74 } 75 76 type UpdateDomainInput struct { 77 // A custom value for the Return-Path domain. It is an optional field, but it must be a subdomain of your From Email domain and must have a CNAME record that points to pm.mtasv.net. For more information about this field, please read our support page. 78 ReturnPathDomain string `json:",omitempty"` 79 } 80 81 func (client *Client) GetDomains(ctx context.Context, count, offset int64) (DomainsList, error) { 82 res := DomainsList{} 83 84 values := &url.Values{} 85 values.Add("count", fmt.Sprintf("%d", count)) 86 values.Add("offset", fmt.Sprintf("%d", offset)) 87 88 err := client.request(ctx, requestParams{ 89 Method: http.MethodGet, 90 URL: fmt.Sprintf("/domains?%s", values.Encode()), 91 }, &res) 92 93 return res, err 94 } 95 96 func (client *Client) GetDomain(ctx context.Context, domainID string) (DetailedDomain, error) { 97 res := DetailedDomain{} 98 err := client.request(ctx, requestParams{ 99 Method: http.MethodGet, 100 URL: fmt.Sprintf("/domains/%s", domainID), 101 }, &res) 102 103 return res, err 104 } 105 106 func (client *Client) CreateDomain(ctx context.Context, input CreateDomainInput) (DetailedDomain, error) { 107 res := DetailedDomain{} 108 err := client.request(ctx, requestParams{ 109 Method: http.MethodPost, 110 URL: "/domains", 111 Payload: input, 112 }, &res) 113 114 return res, err 115 } 116 117 func (client *Client) UpdateDomain(ctx context.Context, domainID string, input UpdateDomainInput) (DetailedDomain, error) { 118 res := DetailedDomain{} 119 err := client.request(ctx, requestParams{ 120 Method: http.MethodPut, 121 URL: fmt.Sprintf("/domains/%s", domainID), 122 Payload: input, 123 }, &res) 124 125 return res, err 126 } 127 128 func (client *Client) DeleteDomain(ctx context.Context, domainID string) error { 129 err := client.request(ctx, requestParams{ 130 Method: http.MethodDelete, 131 URL: fmt.Sprintf("/domains/%s", domainID), 132 }, nil) 133 134 return err 135 } 136 137 func (client *Client) VerifyDKIMStatus(ctx context.Context, domainID string) (DetailedDomain, error) { 138 res := DetailedDomain{} 139 err := client.request(ctx, requestParams{ 140 Method: http.MethodPut, 141 URL: fmt.Sprintf("/domains/%s/verifyDkim", domainID), 142 }, &res) 143 144 return res, err 145 } 146 147 func (client *Client) VerifyReturnPathStatus(ctx context.Context, domainID string) (DetailedDomain, error) { 148 res := DetailedDomain{} 149 err := client.request(ctx, requestParams{ 150 Method: http.MethodPut, 151 URL: fmt.Sprintf("/domains/%s/verifyReturnPath", domainID), 152 }, &res) 153 154 return res, err 155 }