blob: 7d0fa98b7b1658ccf035d41bef572b35ca90fe2f [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 Pitrou0d38f2e2011-05-18 20:02:50 +02006
7ssl = support.import_module("ssl")
R. David Murray87e20742009-05-23 01:30:26 +00008
R. David Murrayeccb2ce2009-05-23 02:36:15 +00009support.requires("network")
R. David Murray87e20742009-05-23 01:30:26 +000010
Antoine Pitroue0650202011-05-18 18:03:09 +020011
12class SmtpTest(unittest.TestCase):
13 testServer = 'smtp.gmail.com'
14 remotePort = 25
15 context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
16
17 def test_connect_starttls(self):
18 support.get_attribute(smtplib, 'SMTP_SSL')
19 with support.transient_internet(self.testServer):
20 server = smtplib.SMTP(self.testServer, self.remotePort)
21 server.starttls(context=self.context)
Antoine Pitroucc9ca222011-05-18 18:04:04 +020022 server.ehlo()
23 server.quit()
Antoine Pitroue0650202011-05-18 18:03:09 +020024
25
R. David Murray87e20742009-05-23 01:30:26 +000026class SmtpSSLTest(unittest.TestCase):
27 testServer = 'smtp.gmail.com'
28 remotePort = 465
Antoine Pitroue0650202011-05-18 18:03:09 +020029 context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
R. David Murray87e20742009-05-23 01:30:26 +000030
31 def test_connect(self):
R. David Murrayeccb2ce2009-05-23 02:36:15 +000032 support.get_attribute(smtplib, 'SMTP_SSL')
Antoine Pitrou6003ff72010-10-13 17:14:16 +000033 with support.transient_internet(self.testServer):
34 server = smtplib.SMTP_SSL(self.testServer, self.remotePort)
Antoine Pitroucc9ca222011-05-18 18:04:04 +020035 server.ehlo()
36 server.quit()
R. David Murray87e20742009-05-23 01:30:26 +000037
Antoine Pitrouc1d52062011-05-07 19:39:37 +020038 def test_connect_default_port(self):
39 support.get_attribute(smtplib, 'SMTP_SSL')
40 with support.transient_internet(self.testServer):
41 server = smtplib.SMTP_SSL(self.testServer)
Antoine Pitroucc9ca222011-05-18 18:04:04 +020042 server.ehlo()
43 server.quit()
Antoine Pitrouc1d52062011-05-07 19:39:37 +020044
Antoine Pitroue0650202011-05-18 18:03:09 +020045 def test_connect_using_sslcontext(self):
46 support.get_attribute(smtplib, 'SMTP_SSL')
47 with support.transient_internet(self.testServer):
48 server = smtplib.SMTP_SSL(self.testServer, self.remotePort, context=self.context)
Antoine Pitroucc9ca222011-05-18 18:04:04 +020049 server.ehlo()
50 server.quit()
Antoine Pitroue0650202011-05-18 18:03:09 +020051
52
R. David Murray87e20742009-05-23 01:30:26 +000053def test_main():
Antoine Pitroue0650202011-05-18 18:03:09 +020054 support.run_unittest(SmtpTest, SmtpSSLTest)
R. David Murray87e20742009-05-23 01:30:26 +000055
56if __name__ == "__main__":
57 test_main()