It's often useful to fetch the raw image data without having to save it to a file first (eg. as serving images by HTTP or sending email attachments)
To do that, we make use of the class StringIO.
import StringIO
# Save the file to a temporary file because that's how email attachments work
output = StringIO.StringIO()
pil_image.save(output, format = "PNG")
email.attach(filename = "whatever.png", mimetype = "image/png", content = output.getvalue())
output.close()
And there you have it!