Visualforce email templates allow you to include visualforce components with allowDML="true"
but there doesn't appear to be any way to actually use DML. From the docs:
You can't use data manipulation language (DML) operations in a “getxxx” method in a controller.
You can't use data manipulation language (DML) operations in a constructor method in a controller.
You can't use the @future annotation in a “getxxx” or “setxxx” method in a controller, or in the constructor for a controller.
That seems to cover all the ways (I assume batch apex is also not allowed). So is there any way to do this?