forked from sendgrid/sendgrid-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
twilio_email.go
41 lines (33 loc) · 1.1 KB
/
twilio_email.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
package sendgrid
import (
"encoding/base64"
"github.com/sendgrid/rest"
)
// TwilioEmailOptions for GetTwilioEmailRequest
type TwilioEmailOptions struct {
Username string
Password string
Endpoint string
Host string
}
// NewTwilioEmailSendClient constructs a new Twilio Email client given a username and password
func NewTwilioEmailSendClient(username, password string) *Client {
request := GetTwilioEmailRequest(TwilioEmailOptions{Username: username, Password: password, Endpoint: "/v3/mail/send"})
request.Method = "POST"
return &Client{request}
}
// GetTwilioEmailRequest create Request
// @return [Request] a default request object
func GetTwilioEmailRequest(twilioEmailOptions TwilioEmailOptions) rest.Request {
credentials := twilioEmailOptions.Username + ":" + twilioEmailOptions.Password
encodedCreds := base64.StdEncoding.EncodeToString([]byte(credentials))
options := options{
Auth: "Basic " + encodedCreds,
Endpoint: twilioEmailOptions.Endpoint,
Host: twilioEmailOptions.Host,
}
if options.Host == "" {
options.Host = "https://email.twilio.com"
}
return requestNew(options)
}