Encode s using the ASCII codec and the surrogateescape error handler, and pass it to the write method of the outfp passed to the BytesGenerator’s constructor.
email.generator/BytesGenerator.write
BytesGenerator.write