Example #1
0
// authHandler works with nginx to determine whether or not a receipient email
// address is valid. If it is, running mail server's information is passed
// back.
func authHandler(w http.ResponseWriter, r *http.Request) {
	toHeader := r.Header.Get("Auth-SMTP-To")
	if toHeader == "" {
		w.Header().Set("Auth-Status", "Unrecognized receipient.")
		w.Header().Set("Auth-Error-Code", "550")
		return
	}

	to := smtpEmailReg.FindStringSubmatch(toHeader)[1]
	if to == "" {
		w.Header().Set("Auth-Status", "Unrecognized receipient.")
		w.Header().Set("Auth-Error-Code", "550")
		return
	}
	if err := validate.Email(to); err != nil {
		// Email address validation failed
		w.Header().Set("Auth-Status", err.Error())
		w.Header().Set("Auth-Error-Code", "550")
		return
	}

	// Email passed validation, send back mail server information
	w.Header().Set("Auth-Status", "OK")
	w.Header().Set("Auth-Server", "127.0.0.1")
	w.Header().Set("Auth-Port", fmt.Sprintf("%d", serverPort))
}
Example #2
0
func createPostFromEmail(to, subject, from string, content []byte) {
	if err := validate.Email(to); err != nil {
		return
	}
}