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 (
appFlag = flag.String("app", "", "run specific app")
cfgFile = flag.String("config", "config.json", "config file")
schedFlag = flag.String("schedule", "", "specific schedule")
slowFlag = flag.Bool("slow", false, "slow process")
testFlag = flag.Bool("test", false, "test run")
debugFlag = flag.Bool("debug", false, "debug")
cfg Config
email *Email
appFlag = flag.String("app", "", "run specific app")
cfgFile = flag.String("config", "config.json", "config file")
schedFlag = flag.String("schedule", "", "specific schedule")
slowFlag = flag.Bool("slow", false, "slow process")
testFlag = flag.Bool("test", false, "test run")
debugFlag = flag.Bool("debug", false, "debug")
testMailFlag = flag.Bool("test-mail", false, "test email setup")
cfg Config
email *Email
)
func main() {
@ -34,6 +35,11 @@ func main() {
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)
if err != nil {
log.Printf("Cannot run schedule (%s)", err)

View File

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

View File

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