2525from tor2web import __version__
2626
2727
28- def sendmail (authenticationUsername , authenticationSecret , fromAddress , toAddress , messageFile , smtpHost , smtpPort = 25 ):
28+ def sendmail (config , messageFile ):
2929 """
3030 Sends an email using SSLv3 over SMTP
3131
@@ -47,18 +47,26 @@ def sendmail(authenticationUsername, authenticationSecret, fromAddress, toAddres
4747 resultDeferred = defer .Deferred ()
4848
4949 senderFactory = ESMTPSenderFactory (
50- authenticationUsername ,
51- authenticationSecret ,
52- fromAddress ,
53- toAddress ,
50+ config . smtpuser . encode ( 'utf-8' ) ,
51+ config . smtppass . encode ( 'utf-8' ) ,
52+ config . smtpmail ,
53+ config . smtpmailto_exceptions ,
5454 messageFile ,
5555 resultDeferred ,
56- contextFactory = contextFactory )
56+ contextFactory = contextFactory ,
57+ requireAuthentication = True ,
58+ requireTransportSecurity = (config .smtpsecurity != 'SSL' ),
59+ retries = 0 ,
60+ timeout = 15 )
5761
58- reactor .connectTCP (smtpHost , smtpPort , senderFactory )
62+ if config .security == "SSL" :
63+ senderFactory = tls .TLSMemoryBIOFactory (contextFactory , True , senderFactory )
64+
65+ reactor .connectTCP (config .smtpdomain , config .smtpport , senderFactory )
5966
6067 return resultDeferred
6168
69+
6270def sendexceptionmail (config , etype , value , tb ):
6371 """
6472 Formats traceback and exception data and emails the error
@@ -67,7 +75,6 @@ def sendexceptionmail(config, etype, value, tb):
6775 @param value: Exception string value
6876 @param tb: Traceback string data
6977 """
70-
7178 exc_type = re .sub ("(<(type|class ')|'exceptions.|'>|__main__.)" , "" , str (etype ))
7279
7380 tmp = ["From: Tor2web Node %s.%s <%s>\n " % (config .nodename , config .basehost , config .smtpmail ),
@@ -86,4 +93,8 @@ def sendexceptionmail(config, etype, value, tb):
8693 info_string = '' .join (tmp )
8794 message = StringIO (info_string )
8895
89- sendmail (config .smtpuser , config .smtppass , config .smtpmail , config .smtpmailto_exceptions , message , config .smtpdomain , config .smtpport )
96+ sendmail (config , message )
97+
98+
99+ def MailException (etype , value , tb ):
100+ sendexceptionmail (config , etype , value , tb )
0 commit comments