-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This reverts commit 462e68f.
- Loading branch information
1 parent
462e68f
commit 017881f
Showing
2 changed files
with
13 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,39 +4,26 @@ package main | |
|
||
import ( | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"net/smtp" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"gopkg.in/gomail.v1" | ||
"os" | ||
) | ||
|
||
var sendMail = sendStdMail | ||
|
||
var useLoginAuth = flag.Bool("L", false, "Use LOGIN auth") | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
if *useLoginAuth { | ||
sendMail = sendLoginMail | ||
} | ||
|
||
t := time.Now() | ||
|
||
f, err := os.OpenFile("feedback"+t.Format("20060102-1504")+".log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) | ||
f, err := os.OpenFile("feedback" + t.Format("20060102-1504") + ".log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
defer f.Close() | ||
log.SetOutput(f) | ||
|
||
if FromAddr == "[email protected]" { | ||
log.Fatal("Please set the constants in config.go and recompile") | ||
} | ||
|
@@ -46,7 +33,7 @@ func main() { | |
} | ||
|
||
http.HandleFunc("/", rootHandler) | ||
|
||
log.Println("Starting server on port", Port) | ||
log.Fatal(http.ListenAndServeTLS(":"+Port, CertificatePath, PrivateKeyPath, nil)) | ||
} | ||
|
@@ -85,8 +72,8 @@ func rootHandler(w http.ResponseWriter, r *http.Request) { | |
decoder := json.NewDecoder(strings.NewReader(fbstr)) | ||
var feedback Feedback | ||
err := decoder.Decode(&feedback) | ||
|
||
if err != nil { | ||
if err != nil { | ||
log.Println("JSON decode error:", err) | ||
} | ||
|
||
|
@@ -110,10 +97,10 @@ func rootHandler(w http.ResponseWriter, r *http.Request) { | |
} | ||
} | ||
|
||
// sendStdMail sends a mail with the given subject and content. The content must have Unix | ||
// sendMail sends a mail with the given subject and content. The content must have Unix | ||
// newlines (\n) and end in a newline. These newlines will be converted to SMTP's CRLF | ||
// automatically. | ||
func sendStdMail(subject, content string) error { | ||
func sendMail(subject, content string) error { | ||
auth := smtp.PlainAuth("", FromAddr, Passwd, SMTPSrv) | ||
to := []string{ToAddr} | ||
date := time.Now().Format(time.RFC822Z) | ||
|
@@ -122,24 +109,5 @@ func sendStdMail(subject, content string) error { | |
body := strings.Replace(content, "\n", "\r\n", -1) | ||
msg := []byte(header + "\r\n" + body) | ||
|
||
return smtp.SendMail(SMTPSrv+":"+Port, auth, FromAddr, to, msg) | ||
} | ||
|
||
// sendLoginMail uses the LOGIN auth implemented using gomail instead. | ||
func sendLoginMail(subject, content string) error { | ||
auth := gomail.LoginAuth(FromAddr, Passwd, SMTPSrv) | ||
mailer := gomail.NewCustomMailer(SMTPSrv+":"+SMTPPort, auth) | ||
|
||
body := strings.Replace(content, "\n", "\r\n", -1) | ||
|
||
msg := gomail.NewMessage() | ||
msg.SetHeaders(map[string][]string{ | ||
"From": {FromAddr}, | ||
"To": {ToAddr}, | ||
"Subject": {subject}, | ||
}) | ||
msg.SetDateHeader("Date", time.Now()) | ||
msg.SetBody("text/plain", body) | ||
|
||
return mailer.Send(msg) | ||
return smtp.SendMail(SMTPSrv+":"+SMTPPort, auth, FromAddr, to, msg) | ||
} |