sendmail: remove demo feature

Signed-off-by: Nicolas Froger <nicolas@kektus.xyz>
This commit is contained in:
Nicolas Froger 2022-08-15 23:36:27 +02:00
parent dd808711ce
commit d56d8a8f2c
Signed by: nicolas
GPG Key ID: 461D87623FDF1E47
5 changed files with 18 additions and 90 deletions

View File

@ -75,7 +75,6 @@ func main() {
viper.SetDefault("CONTACT_REPLY_EMAIL", "noreply@company.com")
viper.SetDefault("CONTACT_REPLY_BCC_EMAIL", "contact@company.com")
viper.SetDefault("EMAIL_SUBJECT", "Thanks to try our product")
viper.SetDefault("DEMO_URL", "http://company.com/product-demo")
viper.SetDefault("SMTP_AUTHENTICATION_ENABLED", true)
host := os.Getenv("HOST")

View File

@ -67,7 +67,7 @@ func NewSendMailRequest(from string, to []string, subject string) *SendMailReque
// Execute processes the actual email sending
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"
subject := "Subject: " + m.subject + "\n"
msg := []byte(from + subject + mime + "\n" + m.body)
@ -229,18 +229,7 @@ func SendMail(httpResp http.ResponseWriter, httpReq *http.Request) {
OriginURI: httpReq.FormValue("requestOrigin"),
}
var recipients []string
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
}
recipients := []string{viper.GetString("CONTACT_REPLY_BCC_EMAIL")}
userData, _ := json.Marshal(contactRequest)
log.Println("New Request:", string(userData))
@ -251,27 +240,17 @@ func SendMail(httpResp http.ResponseWriter, httpReq *http.Request) {
Organization string
Subject string
Message string
DemoURL string
}{
Name: contactRequest.Name,
Email: contactRequest.Email,
Organization: contactRequest.Organization,
Subject: contactRequest.Subject,
Message: contactRequest.Message,
DemoURL: viper.GetString("DEMO_URL"),
}
replyTplFile := ""
if contactRequest.RequestTarget == "demo" {
replyTplFile = viper.GetString("TEMPLATE_DEMO_REQUEST_REPLY")
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"
}
replyTplFile := viper.GetString("TEMPLATE_CONTACT_REQUEST_REPLY")
if replyTplFile == "" {
replyTplFile = "./templates/template_reply_contact_request.txt"
}
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"))
} else {
contactResponse.Status = "success"
if contactRequest.RequestTarget == "demo" {
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."
}
contactResponse.Message = "Thank you for your message."
}
} else {
log.Println(err.Error())

View File

@ -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>

View File

@ -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

View File

@ -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>