Skip to content

Commit

Permalink
Implement Reply-To functionality for automatically adding sender address
Browse files Browse the repository at this point in the history
  • Loading branch information
wneessen committed Mar 2, 2022
1 parent 2893b51 commit 17df8f1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions api/sendform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions form/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 17df8f1

Please sign in to comment.