blob: ca31c1efb0a10642bdd59e2064ec00cd871fc076 [file] [log] [blame]
Benjamin Peterson90f5ba52010-03-11 22:53:45 +00001#!/usr/bin/env python3
R. David Murray87e20742009-05-23 01:30:26 +00002
3import unittest
4from test import support
5import smtplib
Antoine Pitroue0650202011-05-18 18:03:09 +02006import ssl
R. David Murray87e20742009-05-23 01:30:26 +00007
R. David Murrayeccb2ce2009-05-23 02:36:15 +00008support.requires("network")
R. David Murray87e20742009-05-23 01:30:26 +00009
Antoine Pitroue0650202011-05-18 18:03:09 +020010
11class SmtpTest(unittest.TestCase):
12 testServer = 'smtp.gmail.com'
13 remotePort = 25
14 context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
15
16 def test_connect_starttls(self):
17 support.get_attribute(smtplib, 'SMTP_SSL')
18 with support.transient_internet(self.testServer):
19 server = smtplib.SMTP(self.testServer, self.remotePort)
20 server.starttls(context=self.context)
21 server.ehlo()
22 server.quit()
23
24
R. David Murray87e20742009-05-23 01:30:26 +000025class SmtpSSLTest(unittest.TestCase):
26 testServer = 'smtp.gmail.com'
27 remotePort = 465
Antoine Pitroue0650202011-05-18 18:03:09 +020028 context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
R. David Murray87e20742009-05-23 01:30:26 +000029
30 def test_connect(self):
R. David Murrayeccb2ce2009-05-23 02:36:15 +000031 support.get_attribute(smtplib, 'SMTP_SSL')
Antoine Pitrou6003ff72010-10-13 17:14:16 +000032 with support.transient_internet(self.testServer):
33 server = smtplib.SMTP_SSL(self.testServer, self.remotePort)
R. David Murray87e20742009-05-23 01:30:26 +000034 server.ehlo()
35 server.quit()
36
Antoine Pitrouc1d52062011-05-07 19:39:37 +020037 def test_connect_default_port(self):
38 support.get_attribute(smtplib, 'SMTP_SSL')
39 with support.transient_internet(self.testServer):
40 server = smtplib.SMTP_SSL(self.testServer)
41 server.ehlo()
42 server.quit()
43
Antoine Pitroue0650202011-05-18 18:03:09 +020044 def test_connect_using_sslcontext(self):
45 support.get_attribute(smtplib, 'SMTP_SSL')
46 with support.transient_internet(self.testServer):
47 server = smtplib.SMTP_SSL(self.testServer, self.remotePort, context=self.context)
48 server.ehlo()
49 server.quit()
50
51
R. David Murray87e20742009-05-23 01:30:26 +000052def test_main():
Antoine Pitroue0650202011-05-18 18:03:09 +020053 support.run_unittest(SmtpTest, SmtpSSLTest)
R. David Murray87e20742009-05-23 01:30:26 +000054
55if __name__ == "__main__":
56 test_main()