forked from makeless/makeless-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail_team.go
94 lines (86 loc) · 3.45 KB
/
mail_team.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
package makeless_go
import (
"fmt"
"github.com/makeless/makeless-go/mailer"
"github.com/makeless/makeless-go/mailer/basic"
"github.com/makeless/makeless-go/model"
"github.com/matcornic/hermes/v2"
"sync"
)
func (makeless *Makeless) mailTeamInvitation(data map[string]interface{}) (makeless_go_mailer.Mail, error) {
var err error
var name, link, message, messageHtml string
var user = data["user"].(*makeless_go_model.User)
var userInvited = data["userInvited"].(*makeless_go_model.User)
var teamName = data["teamName"].(string)
var teamInvitation = data["teamInvitation"].(*makeless_go_model.TeamInvitation)
var messages = map[string]map[string]string{
"en": {
"subject": fmt.Sprintf(
"%s invited you to %s",
*user.GetName(),
teamName,
),
"intro": fmt.Sprintf(
"%s has invited you to %s.",
*user.GetName(),
teamName,
),
"outro": fmt.Sprintf(
"Note: This invitation was intended for %s. If you were not expecting this invitation, you can ignore this email.",
*teamInvitation.GetEmail(),
),
"instruction": "You can accept or decline this invitation. This invitation will expire in 7 days.",
"button": "View invitation",
},
}
switch userInvited.GetName() {
case nil:
link = fmt.Sprintf("%s/invitation?token=%s", makeless.GetConfig().GetConfiguration().GetMail().GetLink(), *teamInvitation.GetToken())
default:
name = *userInvited.GetName()
link = fmt.Sprintf("%s/settings/team-invitation", makeless.GetConfig().GetConfiguration().GetMail().GetLink())
}
config := hermes.Hermes{
Product: hermes.Product{
Name: makeless.GetConfig().GetConfiguration().GetMail().GetName(),
Link: makeless.GetConfig().GetConfiguration().GetMail().GetLink(),
Logo: makeless.GetConfig().GetConfiguration().GetMail().GetLogo(),
Copyright: makeless.GetConfig().GetConfiguration().GetMail().GetTexts(makeless.GetConfig().GetConfiguration().GetLocale()).GetCopyright(),
},
}
email := hermes.Email{
Body: hermes.Body{
Name: name,
Greeting: makeless.GetConfig().GetConfiguration().GetMail().GetTexts(makeless.GetConfig().GetConfiguration().GetLocale()).GetGreeting(),
Signature: makeless.GetConfig().GetConfiguration().GetMail().GetTexts(makeless.GetConfig().GetConfiguration().GetLocale()).GetSignature(),
Intros: []string{messages[makeless.GetConfig().GetConfiguration().GetLocale()]["intro"]},
Actions: []hermes.Action{
{
Instructions: messages[makeless.GetConfig().GetConfiguration().GetLocale()]["instruction"],
Button: hermes.Button{
Text: messages[makeless.GetConfig().GetConfiguration().GetLocale()]["button"],
Link: link,
Color: makeless.GetConfig().GetConfiguration().GetMail().GetButtonColor(),
TextColor: makeless.GetConfig().GetConfiguration().GetMail().GetButtonTextColor(),
},
},
},
Outros: []string{messages[makeless.GetConfig().GetConfiguration().GetLocale()]["outro"]},
},
}
if message, err = config.GeneratePlainText(email); err != nil {
return nil, err
}
if messageHtml, err = config.GenerateHTML(email); err != nil {
return nil, err
}
return &makeless_go_mailer_basic.Mail{
To: []string{*teamInvitation.GetEmail()},
From: makeless.GetConfig().GetConfiguration().GetMail().GetFrom(),
Subject: messages[makeless.GetConfig().GetConfiguration().GetLocale()]["subject"],
Message: []byte(message),
HtmlMessage: []byte(messageHtml),
RWMutex: new(sync.RWMutex),
}, nil
}