linelen per mime standards from email encoders import encode_base encode_base (msgobjtext msgobj get_payload(if isinstance(textbytes)text text decode('ascii'what email does normallyleaves bytes bytes fails in email pkg on text gen payload is bytes in str in alpha decode to unicode str so text gen works lines [split into lineselse massive line text text replace('\ '''no \ present in but futureproof mewhile textlinetext text[:linelen]text[linelen:lines append(linemsgobj set_payload('\njoin(lines)def fix_text_required(encodingname)"" eworkaround for str/bytes combination errors in email packagemimetext requires different types for different unicode encodings in python due to the different ways it mime-encodes some types of textsee the only other alternative is using generic message and repeating much code""from email charset import charsetbase qp charset charset(encodingnamebodyenc charset body_encoding return bodyenc in (noneqphow email knows what to do for encoding utf others require bytes input data asciilatin others require str class mailsender(mailtool)""send mailformat messageinterface with an smtp serverworks on any machine with python+inetdoesn' use cmdline maila nonauthenticating clientsee mailsenderauth if login required etracesize is num chars of msg text traced =nonebig=all esupports unicode encodings for main text and text parts esupports header encodingboth full headers and email names""def __init__(selfsmtpserver=nonetracesize= )self smtpservername smtpserver or mailconfig smtpservername self tracesize tracesize def sendmessage(selffromtosubjextrahdrsbodytextattachessavemailseparator=(('= 'py\ ')bodytextencoding='us-ascii'attachesencodings=none)""format and send mailblocks callerthread me in guibodytext is main text partattaches is list of filenamesextrahdrs is list of (namevaluetuples to be addedraises uncaught exception if send fails for any reasonsaves sent message text in local file if successfulthe mailtools utility package