2021-10-11 09:18:28 +01:00
|
|
|
package email
|
|
|
|
|
|
|
|
import (
|
2021-11-01 11:00:21 +00:00
|
|
|
"go.m3o.com/client"
|
2021-10-11 09:18:28 +01:00
|
|
|
)
|
|
|
|
|
2021-12-30 08:44:34 +00:00
|
|
|
type Email interface {
|
|
|
|
Send(*SendRequest) (*SendResponse, error)
|
|
|
|
}
|
|
|
|
|
2021-10-11 09:18:28 +01:00
|
|
|
func NewEmailService(token string) *EmailService {
|
|
|
|
return &EmailService{
|
|
|
|
client: client.NewClient(&client.Options{
|
|
|
|
Token: token,
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type EmailService struct {
|
|
|
|
client *client.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send an email by passing in from, to, subject, and a text or html body
|
|
|
|
func (t *EmailService) Send(request *SendRequest) (*SendResponse, error) {
|
2021-12-21 13:18:29 +00:00
|
|
|
|
2021-10-11 09:18:28 +01:00
|
|
|
rsp := &SendResponse{}
|
|
|
|
return rsp, t.client.Call("email", "Send", request, rsp)
|
2021-12-21 13:18:29 +00:00
|
|
|
|
2021-10-11 09:18:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type SendRequest struct {
|
|
|
|
// the display name of the sender
|
|
|
|
From string `json:"from"`
|
|
|
|
// the html body
|
2021-12-21 13:18:29 +00:00
|
|
|
HtmlBody string `json:"html_body"`
|
2021-10-11 09:18:28 +01:00
|
|
|
// an optional reply to email address
|
2021-12-21 13:18:29 +00:00
|
|
|
ReplyTo string `json:"reply_to"`
|
2021-10-11 09:18:28 +01:00
|
|
|
// the email subject
|
|
|
|
Subject string `json:"subject"`
|
|
|
|
// the text body
|
2021-12-21 13:18:29 +00:00
|
|
|
TextBody string `json:"text_body"`
|
2021-10-11 09:18:28 +01:00
|
|
|
// the email address of the recipient
|
|
|
|
To string `json:"to"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type SendResponse struct {
|
|
|
|
}
|