From 17df8f1baee61aea1885f921cc385a9df8aee90d Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Wed, 2 Mar 2022 14:17:23 +0100 Subject: [PATCH] Implement Reply-To functionality for automatically adding sender address --- README.md | 6 ++++++ api/sendform.go | 6 ++++++ form/form.go | 9 ++++++--- server/server.go | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7c60193..23639f5 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ API that can be accessed via JavaScript `Fetch()` or `XMLHttpRequest`. * reCaptcha v2 support * Form field type validation (text, email, number, bool) * Confirmation mail to poster +* Custom Reply-To header based on sending mail address ### Planed features @@ -95,6 +96,9 @@ the JSON syntax of the form configuration is very simple, yet flexible. "message" ] }, + "replyto": { + "field": "email" + }, "confirmation": { "enabled": true, "rcpt_field": "email", @@ -166,6 +170,8 @@ the JSON syntax of the form configuration is very simple, yet flexible. * `name (type: string)`: Field validation identifier * `type (type: string)`: Type of validation to run on field (text, email, nummber, bool) * `required (type: boolean)`: If set to true, the field is required +* `replyto (type: struct)`: The struct for the reply to configuration + * `rcpt_field (type: string)`: Name of the form field holding the reply-to mail sender address * `server (type: struct)`: The struct for the forms mail server configuration * `host (type: string)`: Hostname of the sending mail server * `port (type: uint32)`: Port to connect to on the sending mail server diff --git a/api/sendform.go b/api/sendform.go index 346d644..3a34801 100644 --- a/api/sendform.go +++ b/api/sendform.go @@ -59,6 +59,12 @@ func (r *Route) SendForm(c echo.Context) error { mailMsg.SetHeader("From", sr.FormObj.Sender) mailMsg.SetHeader("To", sr.FormObj.Recipients...) mailMsg.SetHeader("Subject", sr.FormObj.Content.Subject) + if sr.FormObj.ReplyTo.Field != "" { + sf := c.FormValue(sr.FormObj.ReplyTo.Field) + if sf != "" { + mailMsg.SetHeader("Reply-To", sf) + } + } mailBody := "The following form fields have been transmitted:\n" for _, k := range sr.FormObj.Content.Fields { diff --git a/form/form.go b/form/form.go index e520549..9f04e4b 100644 --- a/form/form.go +++ b/form/form.go @@ -23,9 +23,12 @@ type Form struct { Domains []string `fig:"domains" validate:"required"` Id string `fig:"id" validate:"required"` Recipients []string `fig:"recipients" validate:"required"` - Secret string `fig:"secret" validate:"required"` - Sender string `fig:"sender" validate:"required"` - Server struct { + ReplyTo struct { + Field string `json:"field"` + } + Secret string `fig:"secret" validate:"required"` + Sender string `fig:"sender" validate:"required"` + Server struct { Host string `fig:"host" validate:"required"` Port int `fig:"port" default:"25"` Username string diff --git a/server/server.go b/server/server.go index 3e32d09..1b319f2 100644 --- a/server/server.go +++ b/server/server.go @@ -17,7 +17,7 @@ import ( ) // VERSION is the global version string contstant -const VERSION = "0.2.2" +const VERSION = "0.2.3" // Srv represents the server object type Srv struct {