<s> import smtplib <EOL> from email . mime . text import MIMEText <EOL> def send_mail ( host , port , username , password , mail_from , mail_to , mail_subject , mail_content , mail_type , display_from = None ) : <EOL> if isinstance ( mail_content , unicode ) : <EOL> mail_content = mail_content . encode ( '<STR_LIT:utf-8>' ) <EOL> content = MIMEText ( mail_content , mail_type , '<STR_LIT:utf-8>' ) <EOL> content [ '<STR_LIT>' ] = display_from or mail_from <EOL> if isinstance ( mail_to , ( list , tuple ) ) : <EOL> content [ '<STR_LIT>' ] = '<STR_LIT:U+002CU+0020>' . join ( mail_to ) <EOL> else : <EOL> content [ '<STR_LIT>' ] = mail_to <EOL> content [ '<STR_LIT>' ] = mail_subject <EOL> s = smtplib . SMTP ( ) <EOL> s . connect ( host , port ) <EOL> s . login ( username , password ) <EOL> s . sendmail ( mail_from , mail_to , content . as_string ( ) ) <EOL> s . quit ( ) </s>
