-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwelcome.go
More file actions
40 lines (32 loc) · 1.02 KB
/
Copy pathwelcome.go
File metadata and controls
40 lines (32 loc) · 1.02 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
// Copyright (c) Kopexa GmbH
// SPDX-License-Identifier: BUSL-1.1
package comms
import (
"context"
"fmt"
"github.com/kopexa-grc/comms/v2/driver"
)
// SendWelcomeEmail sends a welcome email to a recipient after successful email verification.
// The email contains a personalized welcome message and confirms the successful verification.
func (c *Comms) SendWelcomeEmail(ctx context.Context, recipient Recipient) error {
if err := recipient.Validate(); err != nil {
return fmt.Errorf("invalid recipient: %w", err)
}
text, html, err := Render(recipient.Lang(), "welcome", map[string]string{
"DisplayName": recipient.Name(),
})
if err != nil {
return fmt.Errorf("failed to render welcome email: %w", err)
}
message := driver.Message{
From: c.config.From,
To: []string{recipient.String()},
Subject: Subject("welcome", recipient.Lang()),
Text: text,
HTML: html,
}
if err := c.config.Driver.Send(ctx, message); err != nil {
return fmt.Errorf("failed to send welcome email: %w", err)
}
return nil
}