Repeat email v1

Also adds some badly needed testing infrastructure.
Hmm, fair enough since this relates only to emails.