-
Notifications
You must be signed in to change notification settings - Fork 84
/
email.go
116 lines (96 loc) · 2.32 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"bytes"
"html/template"
"log"
"net/smtp"
"time"
"github.com/amborle/featmap/tmpl"
)
type welcome struct {
AppSiteURL string
Email string
Workspace string
Key string
}
// WelcomeBody ...
func WelcomeBody(w welcome) (string, error) {
data, err := tmpl.Asset("tmpl/welcome.tmpl")
t, err := template.New("").Parse(string(data))
if err != nil {
return "", err
}
buf := new(bytes.Buffer)
if err = t.Execute(buf, w); err != nil {
return "", err
}
return buf.String(), nil
}
type emailBody struct {
AppSiteURL string
Email string
Key string
}
// ChangeEmailBody ...
func ChangeEmailBody(w emailBody) (string, error) {
data, err := tmpl.Asset("tmpl/email.tmpl")
t, err := template.New("").Parse(string(data))
if err != nil {
return "", err
}
buf := new(bytes.Buffer)
if err = t.Execute(buf, w); err != nil {
return "", err
}
return buf.String(), nil
}
func (s *service) SendEmail(smtpServer string, smtpPort string, smtpUser string, smtpPass string, from string, recipient string, subject string, body string) error {
date := time.Now().Format(time.RFC1123)
err := smtp.SendMail(smtpServer+":"+smtpPort,
smtp.PlainAuth("", smtpUser, smtpPass, smtpServer),
from, []string{recipient}, []byte("From: "+from+"\r\nTo: "+recipient+"\r\nSubject: "+subject+"\r\nDate: "+date+"\r\n\r\n"+body))
if err != nil {
log.Printf("smtp error: %s", err)
return err
}
return err
}
type resetPasswordBody struct {
AppSiteURL string
Email string
Key string
}
// ResetPasswordBody ...
func ResetPasswordBody(w resetPasswordBody) (string, error) {
data, err := tmpl.Asset("tmpl/reset.tmpl")
t, err := template.New("").Parse(string(data))
if err != nil {
return "", err
}
buf := new(bytes.Buffer)
if err = t.Execute(buf, w); err != nil {
return "", err
}
return buf.String(), nil
}
// InviteStruct ...
type InviteStruct struct {
AppSiteURL string
Email string
WorkspaceName string
Code string
InvitedBy string
InvitedByEmail string
}
func inviteBody(w InviteStruct) (string, error) {
data, err := tmpl.Asset("tmpl/invite.tmpl")
t, err := template.New("").Parse(string(data))
if err != nil {
return "", err
}
buf := new(bytes.Buffer)
if err = t.Execute(buf, w); err != nil {
return "", err
}
return buf.String(), nil
}