-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorg_invite_accepted.go
More file actions
46 lines (37 loc) · 1.21 KB
/
Copy pathorg_invite_accepted.go
File metadata and controls
46 lines (37 loc) · 1.21 KB
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
// Copyright (c) Kopexa GmbH
// SPDX-License-Identifier: BUSL-1.1
package comms
import (
"context"
"fmt"
"github.com/kopexa-grc/comms/v2/driver"
)
type InviteAcceptedData struct {
InviteeName string
Organization string
}
// SendInviteAcceptedEmail sends a notification email to the inviter when their invitation has been accepted.
func (c *Comms) SendInviteAcceptedEmail(ctx context.Context, recipient Recipient, data InviteAcceptedData) error {
if err := recipient.Validate(); err != nil {
return fmt.Errorf("invalid recipient: %w", err)
}
text, html, err := Render(recipient.Lang(), "org-invite-accepted", map[string]string{
"DisplayName": recipient.Name(),
"InviteeName": data.InviteeName,
"Organization": data.Organization,
})
if err != nil {
return fmt.Errorf("failed to render invite accepted email: %w", err)
}
message := driver.Message{
From: c.config.From,
To: []string{recipient.String()},
Subject: fmt.Sprintf(Subject("org-invite-accepted", recipient.Lang()), data.InviteeName, data.Organization),
Text: text,
HTML: html,
}
if err := c.config.Driver.Send(ctx, message); err != nil {
return fmt.Errorf("failed to send invite accepted email: %w", err)
}
return nil
}