-
Notifications
You must be signed in to change notification settings - Fork 0
/
smtp.go
40 lines (35 loc) · 935 Bytes
/
smtp.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
package config
import (
"encoding/json"
"fmt"
"os"
)
// SMTP contains the fields needed to connect to a SMTP server.
type SMTP struct {
Port int64 `json:"port"`
User string `json:"user"`
Password string `json:"password"`
Host string `json:"host"`
From string `json:"from"`
Alias string `json:"alias"`
}
// FromAddress creates a string suitable for use in an Email's From header.
func (c SMTP) FromAddress() string {
if c.Alias != "" {
return fmt.Sprintf(`"%s" <%s>`, c.Alias, c.From)
}
return fmt.Sprintf("<%s>", c.From)
}
// Address will return a string of the host and port separated by a colon.
func (c SMTP) Address() string {
return fmt.Sprintf("%s:%d", c.Host, c.Port)
}
// ParseSMTPPath will create an SMTP using the given filepath.
func ParseSMTPPath(path string) (c SMTP, err error) {
f, err := os.Open(path)
if err != nil {
return
}
err = json.NewDecoder(f).Decode(&c)
return
}