1package server
2
3import "fmt"
4
5func (s *Server) sendWelcomeMail(email, handle string) error {
6 if s.mail == nil {
7 return nil
8 }
9
10 s.mailLk.Lock()
11 defer s.mailLk.Unlock()
12
13 s.mail.To(email)
14 s.mail.Subject("Welcome to " + s.config.Hostname)
15 s.mail.Plain().Set(fmt.Sprintf("Welcome to %s! Your handle is %s.", email, handle))
16
17 if err := s.mail.Send(); err != nil {
18 return err
19 }
20
21 return nil
22}
23
24func (s *Server) sendPasswordReset(email, handle, code string) error {
25 if s.mail == nil {
26 return nil
27 }
28
29 s.mailLk.Lock()
30 defer s.mailLk.Unlock()
31
32 s.mail.To(email)
33 s.mail.Subject("Password reset for " + s.config.Hostname)
34 s.mail.Plain().Set(fmt.Sprintf("Hello %s. Your password reset code is %s. This code will expire in ten minutes.", handle, code))
35
36 if err := s.mail.Send(); err != nil {
37 return err
38 }
39
40 return nil
41}
42
43func (s *Server) sendPlcTokenReset(email, handle, code string) error {
44 if s.mail == nil {
45 return nil
46 }
47
48 s.mailLk.Lock()
49 defer s.mailLk.Unlock()
50
51 s.mail.To(email)
52 s.mail.Subject("PLC token for " + s.config.Hostname)
53 s.mail.Plain().Set(fmt.Sprintf("Hello %s. Your PLC operation code is %s. This code will expire in ten minutes.", handle, code))
54
55 if err := s.mail.Send(); err != nil {
56 return err
57 }
58
59 return nil
60}
61
62func (s *Server) sendEmailUpdate(email, handle, code string) error {
63 if s.mail == nil {
64 return nil
65 }
66
67 s.mailLk.Lock()
68 defer s.mailLk.Unlock()
69
70 s.mail.To(email)
71 s.mail.Subject("Email update for " + s.config.Hostname)
72 s.mail.Plain().Set(fmt.Sprintf("Hello %s. Your email update code is %s. This code will expire in ten minutes.", handle, code))
73
74 if err := s.mail.Send(); err != nil {
75 return err
76 }
77
78 return nil
79}
80
81func (s *Server) sendEmailVerification(email, handle, code string) error {
82 if s.mail == nil {
83 return nil
84 }
85
86 s.mailLk.Lock()
87 defer s.mailLk.Unlock()
88
89 s.mail.To(email)
90 s.mail.Subject("Email verification for " + s.config.Hostname)
91 s.mail.Plain().Set(fmt.Sprintf("Hello %s. Your email verification code is %s. This code will expire in ten minutes.", handle, code))
92
93 if err := s.mail.Send(); err != nil {
94 return err
95 }
96
97 return nil
98}