MCPcopy Create free account
hub / github.com/ethstorage/es-node / SendEmail

Function SendEmail

ethstorage/email/email.go:57–84  ·  view source on GitHub ↗
(emailSubject, msg string, config EmailConfig, lg log.Logger)

Source from the content-addressed store, hash-verified

55}
56
57func SendEmail(emailSubject, msg string, config EmailConfig, lg log.Logger) error {
58 lg.Info("Sending email notification", "subject", emailSubject)
59
60 emailBody := fmt.Sprintf("Subject: %s\r\n", emailSubject)
61 emailBody += fmt.Sprintf("To: %s\r\n", config.To)
62 emailBody += fmt.Sprintf("From: \"EthStorage\" <%s>\r\n", config.From)
63 localIP := p2p.GetLocalPublicIPv4()
64 if localIP != nil {
65 msg = strings.Replace(msg, "es-node", fmt.Sprintf("the es-node at %s", localIP.String()), 1)
66 }
67 msg += "\n\nSent at: " + time.Now().Format(time.RFC1123Z)
68 emailBody += "\r\n" + msg
69 lg.Debug("Email body", "body", emailBody)
70
71 err := smtp.SendMail(
72 fmt.Sprintf("%s:%d", config.Host, config.Port),
73 smtp.PlainAuth("", config.Username, config.Password, config.Host),
74 config.From,
75 strings.Split(config.To, ","),
76 []byte(emailBody),
77 )
78 if err != nil {
79 lg.Error("Failed to send email", "error", err, "config", config.String())
80 } else {
81 lg.Info("Email notification sent successfully!")
82 }
83 return err
84}

Callers 4

notifyBlobMissingMethod · 0.92
newWorkLoopMethod · 0.92
reportMiningResultMethod · 0.92
mainFunction · 0.92

Calls 3

GetLocalPublicIPv4Function · 0.92
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected