Hey guys,
I started looking at a similar issue with sending badges to users as attached file. I created a tracker https://tracker.moodle.org/browse/MDL-41956 and going to submit a patch soon. If anyone is still interested, you can follow updates there.
Yuliya