#NEWLINE# def send_message( self , message = '' , **kwargs ) : #NEWLINE# #INDENT# 'Send a message to a user.' #NEWLINE# mail = self . connect ( ) #NEWLINE# subject = kwargs . get ( ATTR_TITLE ) #NEWLINE# msg = MIMEText ( message ) #NEWLINE# msg [ 'Subject' ] = subject #NEWLINE# msg [ 'To' ] = self . recipient #NEWLINE# msg [ 'From' ] = self . _sender #NEWLINE# msg [ 'X-Mailer' ] = 'HomeAssistant' #NEWLINE# for _ in range ( self . tries ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# mail . sendmail ( self . _sender , kwargs . recipient , msg . as_string ( ) ) #NEWLINE# break #NEWLINE# #UNINDENT# except smtplib . SMTPException : #NEWLINE# #INDENT# _LOGGER . warning ( 'SMTPException sending mail: retrying connection' ) #NEWLINE# mail . quit ( ) #NEWLINE# mail = self . connect ( ) #NEWLINE# #UNINDENT# #UNINDENT# mail . quit ( )