#NEWLINE# def send( smtpserver , smtpport , user , mailto , passwd , title , msg = None , file_name = None ) : #NEWLINE# #INDENT# msgRoot = MIMEMultipart ( 'related' ) #NEWLINE# msgRoot [ 'From' ] = 'Email_My_PC' #NEWLINE# msgRoot [ 'Subject' ] = title #NEWLINE# if ( msg != None ) : #NEWLINE# #INDENT# msgText = MIMEText ( ( '%s' % msg ) , 'html' , 'utf-8' ) #NEWLINE# msgRoot . attach ( msgText ) #NEWLINE# #UNINDENT# if ( file_name != None ) : #NEWLINE# #INDENT# att = MIMEText ( open ( ( '%s' % file_name ) , 'rb' ) . read ( ) , 'base64' , 'utf-8' ) #NEWLINE# att [ 'Content-Type' ] = 'application/octet-stream' #NEWLINE# att [ 'Content-Disposition' ] = ( 'attachment; filename="%s"' % file_name ) #NEWLINE# msgRoot . attach ( att ) #NEWLINE# #UNINDENT# try_num = 0 #NEWLINE# try_max = 10 #NEWLINE# while 1 : #NEWLINE# #INDENT# try_num += 1 #NEWLINE# try : #NEWLINE# #INDENT# smtp . sendmail ( user , mailto , msgRoot . as_string ( ) ) #NEWLINE# break #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ( smtpport == '25' ) : #NEWLINE# #INDENT# smtp = smtplib . SMTP ( smtpserver , smtpport ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( smtpport == '587' ) : #NEWLINE# #INDENT# smtp = smtplib . SMTP ( smtpserver , smtpport ) #NEWLINE# smtp . ehlo ( ) #NEWLINE# smtp . starttls ( ) #NEWLINE# smtp . ehlo ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# smtp = smtplib . SMTP_SSL ( smtpserver , smtpport ) #NEWLINE# #UNINDENT# #UNINDENT# smtp . login ( msgText , passwd ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# if ( try_num > try_max ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( file_name != None ) : #NEWLINE# #INDENT# path = ( ( os . getcwd ( ) + '\\' ) + file_name ) #NEWLINE# if os . path . exists ( path ) : #NEWLINE# #INDENT# os . remove ( path )