-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemailutils.go
More file actions
43 lines (36 loc) · 969 Bytes
/
emailutils.go
File metadata and controls
43 lines (36 loc) · 969 Bytes
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
package main
import (
"strings"
"github.com/keighl/postmark"
)
func sendEmail(from, to, replyTo, subject, body, tag string, track bool) error {
email := postmark.Email{
From: from,
To: to,
Subject: subject,
// HtmlBody: "...",
TextBody: body,
Tag: tag,
TrackOpens: true,
}
if replyTo != "" {
email.ReplyTo = replyTo
}
_, err := postmarkClient.SendEmail(email)
return err
}
func applyEmailTemplate(template string, params map[string]string) (subject string, body string) {
lines := strings.SplitN(template, "\n", 3)
if len(lines) < 3 || !strings.HasPrefix(lines[0], "Subject: ") || lines[1] != "" {
panic("Invalid email template format")
}
subject = replaceStrings(strings.Replace(lines[0], "Subject: ", "", 1), params)
body = replaceStrings(lines[2], params)
return
}
func replaceStrings(s string, params map[string]string) string {
for k, v := range params {
s = strings.Replace(s, k, v, -1)
}
return s
}