logo

Tested on OpenBSD 6.4

Schedule email dispatching with cron(8) and sendmail(8)

Configure smtpd(8) for outgoing mail.

Create db user(8), add dispatch script to send submitted forms, change owner and group for /home/db/, and a cron(8) table to run that script every five minutes (*/5):

# mkdir -p /home/db/www
# useradd db
#
# cat > /home/db/www/dispatch << EOF
#!/bin/sh
no_dir() { echo "${0##*/}: $1: No such directory" >&2; exit 2; }

DB='/var/www/db/www'
EXP_TIME='3600'
FROM='hi@romanzolotarev.com'
NAME='Roman Zolotarev'
POSTS="$DB/posts"
TOKENS="$DB/tokens"
test -d "$POSTS" || no_dir "$POSTS"
test -d "$TOKENS" || no_dir "$TOKENS"

find "${POSTS}" -type f |
while read -r post
do
 test -f "$post" || break
 sendmail -t -F "$NAME" -f "$FROM" < "$post"
 rm "$post"
done

find "$TOKENS" -type f -cmin "+$(( EXP_TIME / 60 ))" -delete
EOF
#
# chown -R db:db /home/db
# echo '*/5 * * * * /home/db/www/dispatch' > /tmp/tab
# crontab -u db /tmp/tab
#