-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
44 lines (36 loc) · 858 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package azmail
import (
"encoding/base64"
"net/url"
)
const (
apiPath = "/emails:send"
apiVersion = "2023-03-31"
)
// Client for the Azure Email Communication Service.
type Client struct {
u *url.URL
accessKey []byte
senderAddr string
}
// NewClient creates a new client for Azure Email Communication Service.
// Use the provided endpoint, access key, and email address from your communication service.
func NewClient(endpoint, accessKey, senderAddr string) (*Client, error) {
rawKey, err := base64.StdEncoding.DecodeString(accessKey)
if err != nil {
return nil, err
}
u, err := url.Parse(endpoint)
if err != nil {
return nil, err
}
v := url.Values{}
v.Set("api-version", apiVersion)
u.RawQuery = v.Encode()
u.Path = apiPath
return &Client{
u: u,
accessKey: rawKey,
senderAddr: senderAddr,
}, nil
}