not show-stopper def encodeheader(selfheadertextunicodeencoding='utf- ')"" eencode composed non-ascii message headers content per both email and unicode standardsaccording to an optional user setting or utf- header encode adds line breaks in header string automatically if needed""tryheadertext encode('ascii'excepttryhdrobj email header make_header([(headertextunicodeencoding)]headertext hdrobj encode(exceptpass auto splits into multiple cont lines if needed return headertext smtplib may fail if it won' encode to ascii def encodeaddrheader(selfheadertextunicodeencoding='utf- ')"" etry to encode non-ascii names in email addresess per emailmimeand unicode standardsif this fails drop name and use just addr partif cannot even get addressestry to decode as wholeelse smtplib may run into errors when it tries to encode the entire mail as asciiutf- default should work for mostas it formats code points broadlyinserts newlines if too long or hdr encode split names to multiple linesbut this may not catch some lines longer than the cutoff (improve me)as usedmessage as_string formatter won' try to break lines furthersee also decodeaddrheader in mailparser module for the inverse of this""trypairs email utils getaddresses([headertext]split addrs parts encoded [for nameaddr in pairstryname encode('ascii'use as is if okay as ascii except unicodeerrorelse try to encode name part tryuni name encode(unicodeencodinghdr email header make_header([(uniunicodeencoding)]name hdr encode(exceptname none drop nameuse address part only joined email utils formataddr((nameaddr)quote name if need encoded append(joinedfullhdr 'join(encodedif len(fullhdr or '\nin fullhdrfullhdr ',\ join(encodedreturn fullhdr exceptreturn self encodeheader(headertextnot one short linetry multiple lines def authenticateserver(selfserver)the mailtools utility package