-
Notifications
You must be signed in to change notification settings - Fork 12
/
mail_team.go
113 lines (105 loc) · 3.76 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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{}, locale string) (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",
},
"de": {
"subject": fmt.Sprintf(
"%s hat dich zu %s eingeladen.",
*user.GetName(),
teamName,
),
"intro": fmt.Sprintf(
"%s hat dich zu %s eingeladen.",
*user.GetName(),
teamName,
),
"outro": fmt.Sprintf(
"Hinweis: Diese Einladung ist für %s vorgesehen. Bitte ignoriere diese Email, falls du keine Einladung erwartest.",
*teamInvitation.GetEmail(),
),
"instruction": "Du kannst die Einladung annehmen oder ablehnen. Die Einladung ist 7 Tage lang gültig.",
"button": "Einladung ansehen",
},
}
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(locale).GetCopyright(),
TroubleText: makeless.GetConfig().GetConfiguration().GetMail().GetTexts(locale).GetTroubleText(),
},
}
email := hermes.Email{
Body: hermes.Body{
Name: name,
Greeting: makeless.GetConfig().GetConfiguration().GetMail().GetTexts(locale).GetGreeting(),
Signature: makeless.GetConfig().GetConfiguration().GetMail().GetTexts(locale).GetSignature(),
Intros: []string{messages[locale]["intro"]},
Actions: []hermes.Action{
{
Instructions: messages[locale]["instruction"],
Button: hermes.Button{
Text: messages[locale]["button"],
Link: link,
Color: makeless.GetConfig().GetConfiguration().GetMail().GetButtonColor(),
TextColor: makeless.GetConfig().GetConfiguration().GetMail().GetButtonTextColor(),
},
},
},
Outros: []string{messages[locale]["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[locale]["subject"],
Message: []byte(message),
HtmlMessage: []byte(messageHtml),
RWMutex: new(sync.RWMutex),
}, nil
}