sendmail: remove demo feature
Signed-off-by: Nicolas Froger <nicolas@kektus.xyz>
This commit is contained in:
parent
dd808711ce
commit
d56d8a8f2c
1
main.go
1
main.go
|
@ -75,7 +75,6 @@ func main() {
|
||||||
viper.SetDefault("CONTACT_REPLY_EMAIL", "noreply@company.com")
|
viper.SetDefault("CONTACT_REPLY_EMAIL", "noreply@company.com")
|
||||||
viper.SetDefault("CONTACT_REPLY_BCC_EMAIL", "contact@company.com")
|
viper.SetDefault("CONTACT_REPLY_BCC_EMAIL", "contact@company.com")
|
||||||
viper.SetDefault("EMAIL_SUBJECT", "Thanks to try our product")
|
viper.SetDefault("EMAIL_SUBJECT", "Thanks to try our product")
|
||||||
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")
|
||||||
|
|
35
sendmail.go
35
sendmail.go
|
@ -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)
|
||||||
|
@ -229,18 +229,7 @@ func SendMail(httpResp http.ResponseWriter, httpReq *http.Request) {
|
||||||
OriginURI: httpReq.FormValue("requestOrigin"),
|
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))
|
||||||
|
@ -251,27 +240,17 @@ func SendMail(httpResp http.ResponseWriter, httpReq *http.Request) {
|
||||||
Organization 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,
|
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" {
|
|
||||||
replyTplFile = viper.GetString("TEMPLATE_DEMO_REQUEST_REPLY")
|
|
||||||
if replyTplFile == "" {
|
if replyTplFile == "" {
|
||||||
replyTplFile = "./templates/template_reply_demo_request.html"
|
replyTplFile = "./templates/template_reply_contact_request.txt"
|
||||||
}
|
|
||||||
} 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")
|
||||||
|
@ -291,11 +270,7 @@ func SendMail(httpResp http.ResponseWriter, httpReq *http.Request) {
|
||||||
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 or send us an email at %s.", viper.GetString("CONTACT_REPLY_BCC_EMAIL"))
|
||||||
} 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