镜像自地址
https://github.com/betterfor/action-send-mail.git
已同步 2026-11-20 16:37:04 +00:00
Update main.go
这个提交包含在:
61
main.go
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
|
||||||
|
}
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户