<s> from shinymud . data . config import EMAIL_HOST , EMAIL_PORT , EMAIL_HOST_USER , EMAIL_HOST_PASSWORD , EMAIL_USE_TLS <EOL> from email . mime . multipart import MIMEMultipart <EOL> from email . mime . text import MIMEText <EOL> import smtplib <EOL> class ShinyMail ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , to , subject , message = '<STR_LIT>' , from_addr = None ) : <EOL> """<STR_LIT>""" <EOL> self . email = MIMEMultipart ( ) <EOL> self . email [ '<STR_LIT>' ] = subject <EOL> self . email [ '<STR_LIT>' ] = '<STR_LIT:U+002CU+0020>' . join ( to ) <EOL> self . email [ '<STR_LIT>' ] = from_addr or EMAIL_HOST_USER <EOL> self . message = message <EOL> self . files = [ ] <EOL> def attach_text_file ( self , filename , content ) : <EOL> """<STR_LIT>""" <EOL> msg = MIMEText ( content ) <EOL> msg . add_header ( '<STR_LIT>' , '<STR_LIT>' , filename = filename ) <EOL> self . files . append ( msg ) <EOL> def send ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _construct_email ( ) <EOL> con = smtplib . SMTP ( EMAIL_HOST , EMAIL_PORT ) <EOL> con . set_debuglevel ( <NUM_LIT:1> ) <EOL> if EMAIL_USE_TLS : <EOL> con . starttls ( ) <EOL> if EMAIL_HOST_USER and EMAIL_HOST_PASSWORD : <EOL> con . login ( EMAIL_HOST_USER , EMAIL_HOST_PASSWORD ) <EOL> con . sendmail ( self . email [ '<STR_LIT>' ] , self . email [ '<STR_LIT>' ] , self . email . as_string ( ) ) <EOL> con . quit ( ) <EOL> def _construct_email ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . message : <EOL> self . email . attach ( MIMEText ( self . message ) ) <EOL> for f in self . files : <EOL> self . email . attach ( f ) <EOL> if not self . email . get_payload ( ) : <EOL> raise Exception ( "<STR_LIT>" ) </s>
