test email

This commit is contained in:
shoopea 2022-06-19 12:12:00 +08:00
parent 86ddd52642
commit 493715555d
3 changed files with 23 additions and 12 deletions

View File

@ -9,14 +9,15 @@ import (
) )
var ( var (
appFlag = flag.String("app", "", "run specific app") appFlag = flag.String("app", "", "run specific app")
cfgFile = flag.String("config", "config.json", "config file") cfgFile = flag.String("config", "config.json", "config file")
schedFlag = flag.String("schedule", "", "specific schedule") schedFlag = flag.String("schedule", "", "specific schedule")
slowFlag = flag.Bool("slow", false, "slow process") slowFlag = flag.Bool("slow", false, "slow process")
testFlag = flag.Bool("test", false, "test run") testFlag = flag.Bool("test", false, "test run")
debugFlag = flag.Bool("debug", false, "debug") debugFlag = flag.Bool("debug", false, "debug")
cfg Config testMailFlag = flag.Bool("test-mail", false, "test email setup")
email *Email cfg Config
email *Email
) )
func main() { func main() {
@ -34,6 +35,11 @@ func main() {
os.Exit(1) os.Exit(1)
} }
if *testMailFlag {
SendMail(cfg.Email.smtpHost, cfg.Email.fromEmail, "test backup email topic", "test backup email body", cfg.Email.toEmail)
os.Exit(0)
}
err = RunBackup(*appFlag) err = RunBackup(*appFlag)
if err != nil { if err != nil {
log.Printf("Cannot run schedule (%s)", err) log.Printf("Cannot run schedule (%s)", err)

View File

@ -2,6 +2,7 @@ package main
import ( import (
"encoding/base64" "encoding/base64"
"log"
"net/smtp" "net/smtp"
"strings" "strings"
"time" "time"
@ -48,6 +49,10 @@ func SendMail(addr, from, subject, body string, to []string) error {
"Content-Transfer-Encoding: base64\r\n" + "Content-Transfer-Encoding: base64\r\n" +
"\r\n" + base64.StdEncoding.EncodeToString([]byte(body)) "\r\n" + base64.StdEncoding.EncodeToString([]byte(body))
if *debugFlag {
log.Printf("SendMail :\r\n%s", msg)
}
_, err = w.Write([]byte(msg)) _, err = w.Write([]byte(msg))
if err != nil { if err != nil {
return err return err

View File

@ -1,6 +1,6 @@
// Code generated by version.sh (@generated) DO NOT EDIT. // Code generated by version.sh (@generated) DO NOT EDIT.
package main package main
var githash = "7c309b8" var githash = "86ddd52"
var buildstamp = "2022-06-19_03:58:59" var buildstamp = "2022-06-19_04:11:44"
var commits = "42" var commits = "43"
var version = "7c309b8-b42 - 2022-06-19_03:58:59" var version = "86ddd52-b43 - 2022-06-19_04:11:44"