<s> import sys <EOL> import smtplib <EOL> from email . mime . text import MIMEText <EOL> from email . mime . multipart import MIMEMultipart <EOL> DEFAULT_EMAIL_HOST = '<STR_LIT>' <EOL> EMAILS_SENT = [ ] <EOL> def send_email ( app , body_text , subject , from_email , to_email , body_html = None ) : <EOL> email_host = app . config . get ( '<STR_LIT>' , DEFAULT_EMAIL_HOST ) <EOL> if isinstance ( to_email , basestring ) : <EOL> to_email = [ to_email ] <EOL> if app . config . get ( '<STR_LIT>' , False ) or app . config . get ( '<STR_LIT>' , False ) : <EOL> print "<STR_LIT>" % ( app . config . get ( '<STR_LIT>' , False ) , app . config . get ( '<STR_LIT>' , False ) ) <EOL> sys . stdout . flush ( ) <EOL> EMAILS_SENT . append ( body_html ) <EOL> else : <EOL> print "<STR_LIT>" % email_host <EOL> msg = MIMEMultipart ( '<STR_LIT>' ) <EOL> msg [ '<STR_LIT>' ] = subject <EOL> msg [ '<STR_LIT>' ] = from_email <EOL> msg [ '<STR_LIT>' ] = '<STR_LIT:U+002CU+0020>' . join ( to_email ) <EOL> part1 = MIMEText ( body_text , '<STR_LIT:text>' ) <EOL> msg . attach ( part1 ) <EOL> if body_text is not None : <EOL> part2 = MIMEText ( body_html , '<STR_LIT:html>' ) <EOL> msg . attach ( part2 ) <EOL> total_to_email = [ ] <EOL> total_to_email . extend ( to_email ) <EOL> total_to_email . extend ( app . config [ '<STR_LIT>' ] ) <EOL> total_to_email . append ( from_email ) <EOL> s = smtplib . SMTP ( email_host ) <EOL> s . sendmail ( from_email , tuple ( total_to_email ) , msg . as_string ( ) ) <EOL> print "<STR_LIT>" % email_host <EOL> sys . stdout . flush ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> class Fake ( ) : pass <EOL> fake_app = Fake ( ) <EOL> fake_app . config = { } <EOL> send_email ( fake_app , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , """<STR_LIT>""" ) </s>
