by Davo Smith.
Yuliua - simply copy the file out of the Files API into a temporary file in the dataroot folder, using either copy_content_to or (probably more appropriately), copy_content_to_temp. Then, email the file and delete it again.
The time taken to copy the file to the temporary location will be tiny compared to the time taken to actually send the file, so not something to worry about in terms of performance. It could be argued, however, that updating the email_to_user function to accept a 'stored_file' object, as an alternative to a path string, might be a worthwhile addition (in which case, opening / finding an issue on tracker.moodle.org and providing a suitable patch would be a good way forward).