-
Notifications
You must be signed in to change notification settings - Fork 0
/
email.go
45 lines (39 loc) · 783 Bytes
/
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
42
43
44
45
package lmail
import (
"encoding/base64"
"errors"
"net/mail"
"strings"
)
type EmailProvider interface {
Send(data *Data) error
}
type Data struct {
From mail.Address
To []mail.Address
Subject string
Body string
WithLimiter bool
}
func (d *Data) Validate() error {
if d.Subject == `` {
return errors.New("empty email subject")
}
if d.Body == `` {
return errors.New("empty email body")
}
return nil
}
func (d *Data) MakeCc() string {
var out = make([]string, 0, len(d.To))
for i := 1; i < len(d.To); i++ {
out = append(out, d.To[i].String())
}
return strings.Join(out, `, `)
}
func EncodeStr(str string) string {
if len(str) == 0 {
return ``
}
return "=?UTF-8?B?" + base64.StdEncoding.EncodeToString([]byte(str)) + "?="
}