25
25
from tor2web import __version__
26
26
27
27
28
- def sendmail (authenticationUsername , authenticationSecret , fromAddress , toAddress , messageFile , smtpHost , smtpPort = 25 ):
28
+ def sendmail (config , messageFile ):
29
29
"""
30
30
Sends an email using SSLv3 over SMTP
31
31
@@ -47,18 +47,26 @@ def sendmail(authenticationUsername, authenticationSecret, fromAddress, toAddres
47
47
resultDeferred = defer .Deferred ()
48
48
49
49
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 ,
54
54
messageFile ,
55
55
resultDeferred ,
56
- contextFactory = contextFactory )
56
+ contextFactory = contextFactory ,
57
+ requireAuthentication = True ,
58
+ requireTransportSecurity = (config .smtpsecurity != 'SSL' ),
59
+ retries = 0 ,
60
+ timeout = 15 )
57
61
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 )
59
66
60
67
return resultDeferred
61
68
69
+
62
70
def sendexceptionmail (config , etype , value , tb ):
63
71
"""
64
72
Formats traceback and exception data and emails the error
@@ -67,7 +75,6 @@ def sendexceptionmail(config, etype, value, tb):
67
75
@param value: Exception string value
68
76
@param tb: Traceback string data
69
77
"""
70
-
71
78
exc_type = re .sub ("(<(type|class ')|'exceptions.|'>|__main__.)" , "" , str (etype ))
72
79
73
80
tmp = ["From: Tor2web Node %s.%s <%s>\n " % (config .nodename , config .basehost , config .smtpmail ),
@@ -86,4 +93,8 @@ def sendexceptionmail(config, etype, value, tb):
86
93
info_string = '' .join (tmp )
87
94
message = StringIO (info_string )
88
95
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