Switch the mailers to be invoked using ids, not model objects. This makes it easier to support asynchronous mail jobs, as only simple ids need to be persisted.

Fixes #2806
Revert premature merging of #2806

Revert "Switch the mailers to be invoked using ids, not model objects. This makes it easier to support asynchronous mail jobs, as only simple ids need to be persisted."

This reverts commit a3f1d3bbaf841a735a8697133ed12870bb446148.
Use separate databases depending on the value of ENV['TC_AGENT_NUMBER']