1 #-*- encoding: utf-8 -*-
3 import os
, sys
, string
, socket
7 class SMTP_SSL (smtplib
.SMTP
):
8 """ SMTP class over OpenSSL , with default port 465 """
9 def __init__(self
, host
='', port
=465, local_hostname
=None, key
=None, cert
=None):
12 smtplib
.SMTP
.__init
__(self
, host
, port
, local_hostname
)
14 def connect(self
, host
='localhost', port
=465):
15 if not port
and (host
.find(':') == host
.rfind(':')):
18 host
, port
= host
[:i
], host
[i
+1:]
21 raise socket
.error
, "nonnumeric port"
22 if not port
: port
= 654
23 if self
.debuglevel
> 0: print>>stderr
, 'connect:', (host
, port
)
24 msg
= "getaddrinfo returns an empty list"
26 for res
in socket
.getaddrinfo(host
, port
, 0, socket
.SOCK_STREAM
):
27 af
, socktype
, proto
, canonname
, sa
= res
29 self
.sock
= socket
.socket(af
, socktype
, proto
)
30 if self
.debuglevel
> 0: print>>stderr
, 'connect:', (host
, port
)
33 sslobj
= socket
.ssl(self
.sock
, self
.key
, self
.cert
)
34 except socket
.error
, msg
:
35 if self
.debuglevel
> 0:
36 print>>stderr
, 'connect fail:', (host
, port
)
43 raise socket
.error
, msg
46 self
.sock
= smtplib
.SSLFakeSocket(self
.sock
, sslobj
)
47 self
.file = smtplib
.SSLFakeFile(sslobj
);
49 (code
, msg
) = self
.getreply()
50 if self
.debuglevel
> 0: print>>stderr
, "connect:", msg