MCPcopy
hub / github.com/pocketbase/pocketbase / SendRecordAuthAlert

Function SendRecordAuthAlert

mails/record.go:15–49  ·  view source on GitHub ↗

SendRecordAuthAlert sends a new device login alert to the specified auth record.

(app core.App, authRecord *core.Record, info string)

Source from the content-addressed store, hash-verified

13
14// SendRecordAuthAlert sends a new device login alert to the specified auth record.
15func SendRecordAuthAlert(app core.App, authRecord *core.Record, info string) error {
16 mailClient := app.NewMailClient()
17
18 info = html.EscapeString(info)
19
20 subject, body, err := resolveEmailTemplate(app, authRecord, authRecord.Collection().AuthAlert.EmailTemplate, map[string]any{
21 core.EmailPlaceholderAlertInfo: info,
22 })
23 if err != nil {
24 return err
25 }
26
27 message := &mailer.Message{
28 From: mail.Address{
29 Name: app.Settings().Meta.SenderName,
30 Address: app.Settings().Meta.SenderAddress,
31 },
32 To: []mail.Address{{Address: authRecord.Email()}},
33 Subject: subject,
34 HTML: body,
35 }
36
37 event := new(core.MailerRecordEvent)
38 event.App = app
39 event.Mailer = mailClient
40 event.Message = message
41 event.Record = authRecord
42 event.Meta = map[string]any{
43 "info": info,
44 }
45
46 return app.OnMailerRecordAuthAlertSend().Trigger(event, func(e *core.MailerRecordEvent) error {
47 return e.Mailer.Send(e.Message)
48 })
49}
50
51// SendRecordOTP sends OTP email to the specified auth record.
52//

Callers 3

TestSendRecordAuthAlertFunction · 0.92
authAlertFunction · 0.92
SubmitMethod · 0.92

Calls 8

resolveEmailTemplateFunction · 0.85
CollectionMethod · 0.80
EmailMethod · 0.80
TriggerMethod · 0.80
NewMailClientMethod · 0.65
SettingsMethod · 0.65
SendMethod · 0.65

Tested by 1

TestSendRecordAuthAlertFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…