blob: 61ecd74f86add7bf9a7092d63e24e08d63076f50 [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)
Antoine Pitroucc9ca222011-05-18 18:04:04 +020021 server.ehlo()
22 server.quit()
Antoine Pitroue0650202011-05-18 18:03:09 +020023
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)
Antoine Pitroucc9ca222011-05-18 18:04:04 +020034 server.ehlo()
35 server.quit()
R. David Murray87e20742009-05-23 01:30:26 +000036
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)
Antoine Pitroucc9ca222011-05-18 18:04:04 +020041 server.ehlo()
42 server.quit()
Antoine Pitrouc1d52062011-05-07 19:39:37 +020043
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)
Antoine Pitroucc9ca222011-05-18 18:04:04 +020048 server.ehlo()
49 server.quit()
Antoine Pitroue0650202011-05-18 18:03:09 +020050
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()