mirror of
https://github.com/jonathan-martz/pocketbase-php-sdk.git
synced 2026-04-03 07:27:42 +00:00
send mail when failed is bigger then 0
This commit is contained in:
48
mailer.go
48
mailer.go
@@ -68,27 +68,37 @@ func main() {
|
|||||||
log.Fatal("Counts field not found in PHPUnit output.")
|
log.Fatal("Counts field not found in PHPUnit output.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serialize the counts field to JSON for the email body
|
// Check if 'fails' is greater than 0
|
||||||
countsJSON, err := json.MarshalIndent(counts, "", " ")
|
fails, ok := counts["failed"].(float64)
|
||||||
if err != nil {
|
if !ok {
|
||||||
log.Fatalf("Failed to serialize counts to JSON: %v", err)
|
log.Fatal("'fails' field not found in counts.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the email body
|
if fails > 0 {
|
||||||
emailBody := fmt.Sprintf("Subject: %s\r\n\r\n%s", subject, string(countsJSON))
|
// Serialize the counts field to JSON for the email body
|
||||||
|
countsJSON, err := json.MarshalIndent(counts, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to serialize counts to JSON: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Connect to the SMTP server
|
// Prepare the email body
|
||||||
auth := smtp.PlainAuth("", *smtpUser, *smtpPass, smtpHost)
|
emailBody := fmt.Sprintf("Subject: %s\r\n\r\n%s", subject, string(countsJSON))
|
||||||
err = smtp.SendMail(
|
|
||||||
smtpHost+":"+smtpPort,
|
// Connect to the SMTP server
|
||||||
auth,
|
auth := smtp.PlainAuth("", *smtpUser, *smtpPass, smtpHost)
|
||||||
*sender,
|
err = smtp.SendMail(
|
||||||
[]string{recipient},
|
smtpHost+":"+smtpPort,
|
||||||
[]byte(emailBody),
|
auth,
|
||||||
)
|
*sender,
|
||||||
if err != nil {
|
[]string{recipient},
|
||||||
log.Fatalf("Failed to send email: %v", err)
|
[]byte(emailBody),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to send email: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Test results sent to", recipient)
|
||||||
|
} else {
|
||||||
|
log.Println("No failures detected. No email sent.")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Test results sent to", recipient)
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user