Compare commits
5 Commits
7e57bd218f
...
7b340cc6f4
Author | SHA1 | Date |
---|---|---|
Nicolas Froger | 7b340cc6f4 | |
Nicolas Froger | c9f97d5e70 | |
Nicolas Froger | 980ec79dba | |
Nicolas Froger | d56d8a8f2c | |
Nicolas Froger | dd808711ce |
|
@ -0,0 +1,7 @@
|
||||||
|
use_configsh() {
|
||||||
|
watch_file config.sh
|
||||||
|
eval "$(cat config.sh)"
|
||||||
|
}
|
||||||
|
|
||||||
|
use_flake
|
||||||
|
use_configsh
|
|
@ -0,0 +1,43 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"futils": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1656928814,
|
||||||
|
"narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1659526864,
|
||||||
|
"narHash": "sha256-XFzXrc1+6DZb9hBgHfEzfwylPUSqVFJbQPs8eOgYufU=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "478f3cbc8448b5852539d785fbfe9a53304133be",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "nixos-22.05",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"futils": "futils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
{
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05";
|
||||||
|
futils.url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, futils } @ inputs:
|
||||||
|
let
|
||||||
|
inherit (nixpkgs) lib;
|
||||||
|
inherit (lib) recursiveUpdate;
|
||||||
|
inherit (futils.lib) eachDefaultSystem;
|
||||||
|
|
||||||
|
nixpkgsImport = system:
|
||||||
|
import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
};
|
||||||
|
|
||||||
|
defaultSystemOutputs = eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
pkgs = nixpkgsImport system;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
git
|
||||||
|
go
|
||||||
|
];
|
||||||
|
};
|
||||||
|
});
|
||||||
|
in
|
||||||
|
defaultSystemOutputs;
|
||||||
|
}
|
9
main.go
9
main.go
|
@ -17,10 +17,10 @@ limitations under the License.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
@ -72,10 +72,9 @@ func main() {
|
||||||
viper.SetDefault("SMTP_SERVER_ADDR", "127.0.0.1:465")
|
viper.SetDefault("SMTP_SERVER_ADDR", "127.0.0.1:465")
|
||||||
viper.SetDefault("SMTP_CLIENT_USERNAME", "")
|
viper.SetDefault("SMTP_CLIENT_USERNAME", "")
|
||||||
viper.SetDefault("SMTP_CLIENT_PASSWORD", "")
|
viper.SetDefault("SMTP_CLIENT_PASSWORD", "")
|
||||||
viper.SetDefault("CONTACT_REPLY_EMAIL", "noreply@company.com")
|
viper.SetDefault("CONTACT_REPLY_EMAIL", "noreply@example.com")
|
||||||
viper.SetDefault("CONTACT_REPLY_BCC_EMAIL", "contact@company.com")
|
viper.SetDefault("CONTACT_REPLY_BCC_EMAIL", "contact@example.com")
|
||||||
viper.SetDefault("EMAIL_SUBJECT", "Thanks to try our product")
|
viper.SetDefault("EMAIL_SUBJECT", "New message from contact form")
|
||||||
viper.SetDefault("DEMO_URL", "http://company.com/product-demo")
|
|
||||||
viper.SetDefault("SMTP_AUTHENTICATION_ENABLED", true)
|
viper.SetDefault("SMTP_AUTHENTICATION_ENABLED", true)
|
||||||
|
|
||||||
host := os.Getenv("HOST")
|
host := os.Getenv("HOST")
|
||||||
|
|
73
sendmail.go
73
sendmail.go
|
@ -22,12 +22,12 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/dpapathanasiou/go-recaptcha"
|
"github.com/dpapathanasiou/go-recaptcha"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -67,7 +67,7 @@ func NewSendMailRequest(from string, to []string, subject string) *SendMailReque
|
||||||
// Execute processes the actual email sending
|
// Execute processes the actual email sending
|
||||||
func (m *SendMailRequest) Execute() error {
|
func (m *SendMailRequest) Execute() error {
|
||||||
|
|
||||||
mime := "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"
|
mime := "MIME-version: 1.0;\nContent-Type: text/plain; charset=\"UTF-8\";\n\n"
|
||||||
from := "From: " + m.from + "\n"
|
from := "From: " + m.from + "\n"
|
||||||
subject := "Subject: " + m.subject + "\n"
|
subject := "Subject: " + m.subject + "\n"
|
||||||
msg := []byte(from + subject + mime + "\n" + m.body)
|
msg := []byte(from + subject + mime + "\n" + m.body)
|
||||||
|
@ -220,65 +220,40 @@ func SendMail(httpResp http.ResponseWriter, httpReq *http.Request) {
|
||||||
httpReq.ParseForm()
|
httpReq.ParseForm()
|
||||||
|
|
||||||
contactRequest := ContactRequest{
|
contactRequest := ContactRequest{
|
||||||
Name: httpReq.FormValue("name"),
|
Name: httpReq.FormValue("name"),
|
||||||
Email: strings.TrimSpace(httpReq.FormValue("email")),
|
Email: strings.TrimSpace(httpReq.FormValue("email")),
|
||||||
Organization: httpReq.FormValue("organization"),
|
Subject: httpReq.FormValue("subject"),
|
||||||
Subject: httpReq.FormValue("subject"),
|
Message: httpReq.FormValue("message"),
|
||||||
Message: httpReq.FormValue("message"),
|
OriginURI: httpReq.FormValue("requestOrigin"),
|
||||||
RequestTarget: httpReq.FormValue("target"),
|
|
||||||
OriginURI: httpReq.FormValue("requestOrigin"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var recipients []string
|
recipients := []string{viper.GetString("CONTACT_REPLY_BCC_EMAIL")}
|
||||||
switch contactRequest.RequestTarget {
|
|
||||||
case "demo":
|
|
||||||
recipients = []string{contactRequest.Email, viper.GetString("CONTACT_REPLY_BCC_EMAIL")}
|
|
||||||
case "contact":
|
|
||||||
recipients = []string{viper.GetString("CONTACT_REPLY_BCC_EMAIL")}
|
|
||||||
default:
|
|
||||||
log.Println("not allowed request type:", contactRequest.RequestTarget)
|
|
||||||
httpResp.WriteHeader(http.StatusForbidden)
|
|
||||||
httpResp.Write([]byte(`{"status": "error", "message": "unauthorized request"}`))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
userData, _ := json.Marshal(contactRequest)
|
userData, _ := json.Marshal(contactRequest)
|
||||||
log.Println("New Request:", string(userData))
|
log.Println("New Request:", string(userData))
|
||||||
|
|
||||||
templateData := struct {
|
templateData := struct {
|
||||||
Name string
|
Name string
|
||||||
Email string
|
Email string
|
||||||
Organization string
|
Subject string
|
||||||
Subject string
|
Message string
|
||||||
Message string
|
|
||||||
DemoURL string
|
|
||||||
}{
|
}{
|
||||||
Name: contactRequest.Name,
|
Name: contactRequest.Name,
|
||||||
Email: contactRequest.Email,
|
Email: contactRequest.Email,
|
||||||
Organization: contactRequest.Organization,
|
Subject: contactRequest.Subject,
|
||||||
Subject: contactRequest.Subject,
|
Message: contactRequest.Message,
|
||||||
Message: contactRequest.Message,
|
|
||||||
DemoURL: viper.GetString("DEMO_URL"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
replyTplFile := ""
|
replyTplFile := viper.GetString("TEMPLATE_CONTACT_REQUEST_REPLY")
|
||||||
if contactRequest.RequestTarget == "demo" {
|
if replyTplFile == "" {
|
||||||
replyTplFile = viper.GetString("TEMPLATE_DEMO_REQUEST_REPLY")
|
replyTplFile = "./templates/template_reply_contact_request.txt"
|
||||||
if replyTplFile == "" {
|
|
||||||
replyTplFile = "./templates/template_reply_demo_request.html"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
replyTplFile = viper.GetString("TEMPLATE_CONTACT_REQUEST_REPLY")
|
|
||||||
if replyTplFile == "" {
|
|
||||||
replyTplFile = "./templates/template_reply_contact_request.html"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contactEmail := viper.GetString("CONTACT_REPLY_EMAIL")
|
contactEmail := viper.GetString("CONTACT_REPLY_EMAIL")
|
||||||
sendMailReq := NewSendMailRequest(
|
sendMailReq := NewSendMailRequest(
|
||||||
contactEmail,
|
contactEmail,
|
||||||
recipients,
|
recipients,
|
||||||
contactRequest.Subject,
|
viper.GetString("EMAIL_SUBJECT"),
|
||||||
)
|
)
|
||||||
err := sendMailReq.ParseTemplate(replyTplFile, templateData)
|
err := sendMailReq.ParseTemplate(replyTplFile, templateData)
|
||||||
|
|
||||||
|
@ -288,14 +263,10 @@ func SendMail(httpResp http.ResponseWriter, httpReq *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
contactResponse.Status = "error"
|
contactResponse.Status = "error"
|
||||||
contactResponse.Message = fmt.Sprintf("An internal error occurred, please try later or send us an email at %s.", viper.GetString("CONTACT_REPLY_BCC_EMAIL"))
|
contactResponse.Message = fmt.Sprintf("An internal error occurred, please try later.")
|
||||||
} else {
|
} else {
|
||||||
contactResponse.Status = "success"
|
contactResponse.Status = "success"
|
||||||
if contactRequest.RequestTarget == "demo" {
|
contactResponse.Message = "Thank you for your message."
|
||||||
contactResponse.Message = "Thank you, if you supplied a correct email address then an email should have been sent to you."
|
|
||||||
} else {
|
|
||||||
contactResponse.Message = "Thank you, if you supplied a correct email address then we'll process your request within the next 48 hours."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<p>Hi,</p>
|
|
||||||
<p>A new contact request has been submitted by Mr/Mrs {{.Name}}.</p>
|
|
||||||
<ul>
|
|
||||||
<li>Name: {{.Name}}</li>
|
|
||||||
<li>Email: {{.Email}}</li>
|
|
||||||
<li>Organization: {{.Organization}}</li>
|
|
||||||
<li>Subject: {{.Subject}}</li>
|
|
||||||
<li>Message: {{.Message}}</li>
|
|
||||||
</ul>
|
|
||||||
--
|
|
||||||
<p>This is an automatic email from Krossboard's website.</p>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
Hello,
|
||||||
|
|
||||||
|
A new message has been received on the contact form.
|
||||||
|
|
||||||
|
Name: {{.Name}}
|
||||||
|
Email: {{.Email}}
|
||||||
|
Subject: {{.Subject}}
|
||||||
|
|
||||||
|
{{.Message}}
|
||||||
|
|
||||||
|
--
|
||||||
|
Automatic email from F5KCK Website
|
|
@ -1,36 +0,0 @@
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<p>Dear Mr/Mrs {{.Name}},</p>
|
|
||||||
<p>
|
|
||||||
Thank you for your interest in our products.
|
|
||||||
You'll find below information to get access to the demo platform.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<li>URL: <a href="{{.DemoURL}}">{{.DemoURL}}</a></li>
|
|
||||||
<li>Login: demo</li>
|
|
||||||
<li>Password: password</li>
|
|
||||||
</ul>
|
|
||||||
<p>Enjoy and don't hesitate to contact us if you do have any feedback.</p>
|
|
||||||
<p>
|
|
||||||
Kind regards,<br/>
|
|
||||||
The Customer Service Team
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<hr />
|
|
||||||
<legend>Summary of your request</legend>
|
|
||||||
<ul>
|
|
||||||
<li>Name: {{.Name}}</li>
|
|
||||||
<li>Email: {{.Email}}</li>
|
|
||||||
<li>Organization: {{.Organization}}</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue