-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_email.go
More file actions
50 lines (41 loc) · 1.04 KB
/
Copy pathverify_email.go
File metadata and controls
50 lines (41 loc) · 1.04 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
47
48
49
50
// Copyright (c) Kopexa GmbH
// SPDX-License-Identifier: BUSL-1.1
package comms
import (
"context"
"html/template"
"github.com/kopexa-grc/comms/v2/driver"
)
type verifyEmailData struct {
CommonData
DisplayName string `json:"display_name"`
URL template.URL `json:"URL"`
}
func (c *Comms) SendVerifyEmail(ctx context.Context, r Recipient, url string) error {
data := verifyEmailData{
CommonData: CommonData{
Subject: Subject("verify-email", r.Lang()),
Recipient: r,
},
DisplayName: r.Name(),
URL: template.URL(url), // nolint:gosec
}
msg, err := c.newVerifyEmail(data)
if err != nil {
return err
}
return c.config.Driver.Send(ctx, msg)
}
func (c *Comms) newVerifyEmail(data verifyEmailData) (driver.Message, error) {
text, html, err := Render(data.Recipient.Lang(), "verify-email", data)
if err != nil {
return driver.Message{}, err
}
return driver.Message{
From: c.config.From,
To: []string{data.Recipient.String()},
Subject: data.Subject,
Text: text,
HTML: html,
}, nil
}