diff --git a/README.md b/README.md index 7e4e61d..b744d35 100644 Binary files a/README.md and b/README.md differ diff --git a/smtp.go b/smtp.go index 4b5fc2b..9231ca8 100644 --- a/smtp.go +++ b/smtp.go @@ -13,19 +13,39 @@ func init() { type SMTP struct{} +type options struct { + Subject string `js:"subject"` + Message string `js:"message"` + UDW []string `js:"udw"` +} + func check(e error) { if e != nil { fmt.Println(e) } } -func plainAuth(host string, password string, fromMail string) smtp.Auth { - return smtp.PlainAuth("", fromMail, password, host) +func plainAuth(host string, password string, sender string) smtp.Auth { + return smtp.PlainAuth("", sender, password, host) } -func (*SMTP) SendMail(host string, port string, fromMail string, password string, udwList []string, message string) { - body := []byte(message) - auth := plainAuth(host, password, fromMail) - err := smtp.SendMail(host+":"+port, auth, fromMail, udwList, body) +func (*SMTP) SendMail(host string, port string, sender string, password string, recipient string, options options) { + emailMessage := "From: " + sender + "\r\n" + "To: " + recipient + "\r\n" + + if options.Subject != "" { + emailMessage += "Subject: " + options.Subject + "\r\n\r\n" + } + + if options.Message != "" { + emailMessage += options.Message + } + + if len(options.UDW) == 0 { + options.UDW = []string{recipient} + } + + body := []byte(emailMessage) + auth := plainAuth(host, password, sender) + err := smtp.SendMail(host+":"+port, auth, sender, options.UDW, body) check(err) }