Update main.go

这个提交包含在:
accent
2022-10-10 09:31:04 +08:00
提交者 GitHub
父节点 d74b10b901
当前提交 faa7cf41d8

61
main.go
查看文件

@ -3,44 +3,35 @@ package main
import ( import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"github.com/russross/blackfriday"
"github.com/spf13/viper"
"gopkg.in/gomail.v2"
"io/ioutil" "io/ioutil"
"os" "os"
"strconv"
"strings" "strings"
"time" "time"
"github.com/russross/blackfriday"
"gopkg.in/gomail.v2"
) )
func init() {
viper.AutomaticEnv()
viper.SetEnvPrefix("INPUT_")
}
func main() { func main() {
//viper.ReadInConfig() mailHost := os.Getenv("INPUT_SERVER_ADDRESS")
mailPort := convertInt(os.Getenv("INPUT_SERVER_PORT"))
fmt.Println(os.Environ()) secure := convertBool(os.Getenv("INPUT_SECURE"))
username := os.Getenv("INPUT_USERNAME")
fmt.Println(viper.AllKeys()) password := os.Getenv("INPUT_PASSWORD")
mailHost := viper.GetString("server_address") subject := os.Getenv("INPUT_SUBJECT")
mailPort := viper.GetInt("server_port") to := strings.Split(os.Getenv("INPUT_TO"), ",")
secure := viper.GetBool("secure") from := os.Getenv("INPUT_FROM")
username := viper.GetString("username") body := os.Getenv("INPUT_BODY")
password := viper.GetString("password") htmlBody := os.Getenv("INPUT_HTML_BODY")
subject := viper.GetString("subject") cc := strings.Split(os.Getenv("INPUT_CC"), ",")
to := strings.Split(viper.GetString("to"), ",") bcc := strings.Split(os.Getenv("INPUT_BCC"), ",")
from := viper.GetString("from") replyTo := os.Getenv("INPUT_REPLY_TO")
body := viper.GetString("body") inReplyTo := os.Getenv("INPUT_IN_REPLY_TO")
htmlBody := viper.GetString("html_body")
cc := strings.Split(viper.GetString("cc"), ",")
bcc := strings.Split(viper.GetString("bcc"), ",")
replyTo := viper.GetString("reply_to")
inReplyTo := viper.GetString("in_reply_to")
//ignoreCert := viper.GetBool("ignore_cert") //ignoreCert := viper.GetBool("ignore_cert")
convertMarkdown := viper.GetBool("convert_markdown") convertMarkdown := convertBool(os.Getenv("INPUT_CONVERT_MARKDOWN"))
attachments := strings.Split(viper.GetString("attachments"), ",") attachments := strings.Split(os.Getenv("INPUT_ATTACHMENTS"), ",")
priority := viper.GetString("priority") priority := os.Getenv("INPUT_PRIORITY")
m := gomail.NewMessage() m := gomail.NewMessage()
m.SetHeader("Subject", subject) m.SetHeader("Subject", subject)
@ -96,3 +87,13 @@ func getBody(bodyOrFile string, convertMarkdown bool) string {
return body return body
} }
func convertBool(b string) bool {
b = strings.ToLower(b)
return b == "true" || b == "yes" || b == "1"
}
func convertInt(i string) int {
ints,_ := strconv.Atoi(i)
return ints
}