mirror of
https://github.com/jonathan-martz/pocketbase-php-sdk.git
synced 2026-04-03 07:27:42 +00:00
tdd - refactor mailer go
This commit is contained in:
21
mailer.go
21
mailer.go
@@ -3,9 +3,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"flag"
|
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
// Define flags
|
// Define flags
|
||||||
smtpPass := flag.String("password", "", "SMTP password")
|
smtpPass := flag.String("password", "", "SMTP password")
|
||||||
sender := flag.String("sender", "", "SMTP sender")
|
sender := flag.String("sender", "", "SMTP sender")
|
||||||
smtpUser := flag.String("user", "", "SMTP username")
|
smtpUser := flag.String("user", "", "SMTP username")
|
||||||
@@ -22,17 +22,22 @@ func main() {
|
|||||||
// Parse the flags
|
// Parse the flags
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Check if password is provided
|
// Check if required flags are provided
|
||||||
if *smtpPass == "" {
|
if *smtpPass == "" {
|
||||||
fmt.Println("Error: Password is required. Use -password flag.")
|
log.Fatal("Error: Password is required. Use -password flag.")
|
||||||
return
|
}
|
||||||
|
if *smtpUser == "" {
|
||||||
|
log.Fatal("Error: SMTP username is required. Use -user flag.")
|
||||||
|
}
|
||||||
|
if *sender == "" {
|
||||||
|
log.Fatal("Error: Sender email is required. Use -sender flag.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format the date as YYYY-MM-DD
|
// Format the date as YYYY-MM-DD
|
||||||
currentDate := now.Format("01.02.2006")
|
currentDate := now.Format("01-02-2006")
|
||||||
|
|
||||||
recipient := "support@jonathan-martz.de"
|
recipient := "support@jonathan-martz.de"
|
||||||
subject := "PHPUnit - PocketBase PHP SDK -" + currentDate
|
subject := "PHPUnit - PocketBase PHP SDK - " + currentDate
|
||||||
smtpHost := "smtps.udag.de" // Replace with your SMTP host
|
smtpHost := "smtps.udag.de" // Replace with your SMTP host
|
||||||
smtpPort := "587" // Replace with your SMTP port
|
smtpPort := "587" // Replace with your SMTP port
|
||||||
|
|
||||||
@@ -63,6 +68,8 @@ func main() {
|
|||||||
log.Fatal("Counts field not found in PHPUnit output.")
|
log.Fatal("Counts field not found in PHPUnit output.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println(output.String())
|
||||||
|
|
||||||
// Serialize the counts field to JSON for the email body
|
// Serialize the counts field to JSON for the email body
|
||||||
countsJSON, err := json.MarshalIndent(counts, "", " ")
|
countsJSON, err := json.MarshalIndent(counts, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user