func setup(c *caddy.Controller) error {
	mc, err := parse(c)
	if err != nil {
		return err
	}
	if c.ServerBlockKeyIndex == 0 {
		if mc.maillog, err = mc.maillog.Init(c.ServerBlockKeys...); err != nil {
			return err
		}
		if err = mc.loadFromEnv(); err != nil {
			return err
		}
		if err = mc.loadPGPKeys(); err != nil {
			return err
		}
		if err = mc.loadTemplate(); err != nil {
			return err
		}
		if err = mc.pingSMTP(); err != nil {
			return err
		}
		c.ServerBlockStorage = newHandler(mc, startMailDaemon(mc))
	}
	c.OnShutdown(func() error {
		if moh, ok := c.ServerBlockStorage.(*handler); ok {
			if moh.reqPipe != nil {
				close(moh.reqPipe)
				moh.reqPipe = nil
			}
		}
		return nil
	})
	if moh, ok := c.ServerBlockStorage.(*handler); ok {  
		httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
			moh.Next = next
			return moh
		})
		return nil
	}
	return errors.New("[mailout] Could not create the middleware handler")
}
setup used internally by Caddy to set up this middleware
package mailout
import (
	"errors"
	"strconv"
	"time"
	"github.com/SchumacherFM/mailout/maillog"
	"github.com/caddyserver/caddy"
	"github.com/caddyserver/caddy/caddyhttp/httpserver"
)
func init() {
	caddy.RegisterPlugin("mailout", caddy.Plugin{
		ServerType: "http",
		Action:     setup,
	})
}