#!/usr/local/bin/python import os from email.Message import Message subject = "------------------------------------------------------------------- ---" message = Message() message['subject'] = subject msg = message.as_string() print msg testTxt = open("./test.txt", mode='w') testTxt.write(msg) testTxt.close()