Skip to content

Releases: torrayne/formailer

Back to Go 1.15

05 Mar 17:03
Compare
Choose a tag to compare
Back to Go 1.15 Pre-release
Pre-release

Go 1.16 embeds aren't well supported. So I've gone back to go generate for now.

Complex submission data

01 Mar 18:20
Compare
Choose a tag to compare
Pre-release

In the interest of supporting more complex submissions, we've changed Submission.Values from map[string]string to map[string]interface{}. I'm not a huge fan of interface{} but I think it's the only way to do this.

The default template now supports arrays along with the first template function: IsSlice. I will be adding functions as I need them in my own work or if requested.

The customization update

26 Feb 00:27
Compare
Choose a tag to compare
Pre-release

This is a large update with breaking changes. Up until now Formailer has been very rigid. Simple but rigid. This update hopes to solve that with configuration options.

Forms

Previously you could only set form options in the ENV. Now you set them in your code before your handler runs.

// Vercel Example
package main

import (
	"net/http"

	"github.com/djatwood/formailer"
)

// Formailer handles all form submissions
func Formailer(w http.ResponseWriter, r *http.Request) {
	cfg := make(formailer.Config)
	cfg.Set(
		&formailer.Form{
			To:       "[email protected]",
			From:     `"Company" <[email protected]>`,
			Subject:  "New Submission",
			Redirect: "/success",
		}, &formailer.Form{
			Name:     "Contact",
			To:       "[email protected]",
			From:     `"Company" <[email protected]>`,
			Subject:  "New Contact Submission",
			Redirect: "https://domin.com/thankyou",
		},
	)

	cfg.Vercel(w, r)
}

SMTP

SMTP config is still all done through the ENV but now you can add an SMTP config per form.

# Default
SMTP_HOST=mail.example.com
SMTP_PORT=587
SMTP_USER=[email protected]
SMTP_PASS=mysupersecretpassword

# Overrides
SMTP_CONTACT_USER=[email protected]
SMTP_CONTACT_PASS=youcantguessthispassword

We check first for SMTP_FORM-NAME_FIELD and if that isn't set we use SMTP_FIELD. You can override all four SMTP vars.

Templates

Forms have a new optional variable for Go HTML templates.

cfg := make(formailer.Config)
cfg.Set(&formailer.Form{
	To:       "[email protected]",
	From:     `"Company" <[email protected]>`,
	Subject:  "New Submission",
	Redirect: "/success",
	Template: defaultTemplate,
}

defaultTemplate := `
<html>
<head>
    <style>
        h3 {
            color: #000;
            margin-bottom: 5px;
        }

        p {
            color: #333;
            margin-bottom: 2rem;
        }
    </style>
</head>
<body>
    {{ range $name, $value := .Values }}
    <h3>{{$name}}</h3>
    <p>{{$value}}</p>
    {{ end }}
</body>
</html>
`

Custom Handlers

I've provided pre-built serverless functions for both Netlify and Vercel. But now you can build you own.

func Handler(w http.ResponseWriter, r *http.Request) {
	// pre-processing, check HTTP method

	// parse body
	submission, err := c.Parse(r.Header.Get("Content-Type"), body.String())
	// check for EOF when submitting as multipart/form-data
	if err != nil && err != io.EOF {
		// handle error
		return
	}

	// manipulate data, check honey pot fields

	// Get SMTP server from env
	server, err := submission.Form.SMTPServer()
	if err != nil {
		// handle error
		return
	}

	// Send email
	err = submission.Send(server)
	if err != nil {
		// handle error
		return
	}

	// handle success
}

Added Vercel Support

24 Feb 04:25
Compare
Choose a tag to compare
Added Vercel Support Pre-release
Pre-release
v0.2.0

Updated README

Pre-release 3

17 Jan 01:11
Compare
Choose a tag to compare
Pre-release 3 Pre-release
Pre-release

I still can't fix the whole every email is attached to the same thread. But I think that's the last thing.

Pre-release 2

17 Jan 00:45
91920a6
Compare
Choose a tag to compare
Pre-release 2 Pre-release
Pre-release

All the content types are supported. Redirects are applied as soon as possible.

Redirects

16 Jan 22:33
Compare
Choose a tag to compare
Redirects Pre-release
Pre-release
v0.1.8

Fixed incorrect status when redirecting

Pre-release 1

16 Jan 22:25
Compare
Choose a tag to compare
Pre-release 1 Pre-release
Pre-release
v0.1.7

Refactor and better error handling