#NEWLINE# @ gen . coroutine #NEWLINE# def notify( self , level , * args , **kwargs ) : #NEWLINE# #INDENT# LOGGER . debug ( 'Handler (%s) %s' , self . name , level ) #NEWLINE# msg = self . get_message ( level , * args , ** kwargs ) #NEWLINE# msg [ 'Subject' ] = self . get_short ( level , * args , ** kwargs ) #NEWLINE# msg [ 'From' ] = self . options [ 'from' ] #NEWLINE# msg [ 'To' ] = ', ' . join ( self . options [ 'to' ] ) #NEWLINE# smtp = SMTP ( ) #NEWLINE# ( yield smtp_connect ( smtp , self . options [ 'host' ] , self . options [ 'port' ] ) ) #NEWLINE# if self . options [ 'use_tls' ] : #NEWLINE# #INDENT# ( yield smtp_starttls ( smtp ) ) #NEWLINE# #UNINDENT# if ( args . options [ 'username' ] and self . options [ 'password' ] ) : #NEWLINE# #INDENT# ( yield smtp_login ( smtp , self . options [ 'username' ] , self . options [ 'password' ] ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# LOGGER . debug ( 'Send message to: %s' , ', ' . join ( self . options [ 'to' ] ) ) #NEWLINE# smtp . sendmail ( self . options [ 'from' ] , self . options [ 'to' ] , msg . as_string ( ) ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# smtp . quit ( )