Skip to content

Commit

Permalink
Function updated. README updated
Browse files Browse the repository at this point in the history
  • Loading branch information
gpiechnik2 committed Jul 17, 2022
1 parent 58fe437 commit cfceb78
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Binary file modified README.md
Binary file not shown.
32 changes: 26 additions & 6 deletions smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit cfceb78

Please sign in to comment.