def test_send_auth(self): from email import message_from_string mailer, smtp = self._makeOne() fromaddr = '*****@*****.**' toaddrs = ('*****@*****.**', '*****@*****.**') headers = 'Headers: headers' body = 'bodybodybody\n-- \nsig\n' msgtext = headers + '\n\n' + body msg = message_from_string(msgtext) mailer.username = '******' mailer.password = '******' mailer.hostname = 'spamrelay' mailer.port = 31337 mailer.send(fromaddr, toaddrs, msg) self.assertEqual(len(smtp._inst), 1) inst = smtp._inst[0] self.assertEqual(inst.username, 'foo') self.assertEqual(inst.password, 'evil') self.assertEqual(inst.hostname, 'spamrelay') self.assertEqual(inst.port, '31337') self.assertEqual(inst.fromaddr, fromaddr) self.assertEqual(inst.toaddrs, toaddrs) self.assertTrue(body.encode('ascii') in inst.msgtext) self.assertTrue(headers.encode('ascii') in inst.msgtext) self.assertTrue(inst.quitted) self.assertTrue(inst.closed)
def test_send_commandline_recipients(self): from email.message import Message mailer = self._makeOne() fromaddr = '*****@*****.**' toaddrs = ('*****@*****.**', '*****@*****.**') msg = Message() msg['Headers'] = 'headers' msg.set_payload('bodybodybody\n-- \nsig\n') mailer.send(fromaddr, toaddrs, msg) self.assertEqual( ["/usr/sbin/sendmail", "-t", "-i", "-f", "*****@*****.**", "*****@*****.**", "*****@*****.**"], mailer.popens[0].args[0])
def test_send_commandline_recipients(self): from email.message import Message mailer = self._makeOne() fromaddr = '*****@*****.**' toaddrs = ('*****@*****.**', '*****@*****.**') msg = Message() msg['Headers'] = 'headers' msg.set_payload('bodybodybody\n-- \nsig\n') mailer.send(fromaddr, toaddrs, msg) self.assertEqual([ "/usr/sbin/sendmail", "-t", "-i", "-f", "*****@*****.**", "*****@*****.**", "*****@*****.**" ], mailer.popens[0].args[0])
def test_send(self): from email.message import Message for run in (1, 2): if run == 2: mailer, smtp = self._makeOne(port=25) else: mailer, smtp = self._makeOne() fromaddr = '*****@*****.**' toaddrs = ('*****@*****.**', '*****@*****.**') msg = Message() msg['Headers'] = 'headers' msg.set_payload('bodybodybody\n-- \nsig\n') mailer.send(fromaddr, toaddrs, msg) self.assertEqual(len(smtp._inst), 1) inst = smtp._inst[0] self.assertEqual(inst.fromaddr, fromaddr) self.assertEqual(inst.toaddrs, toaddrs) self.assertEqual(inst.msgtext, msg.as_string().encode('ascii')) self.assertTrue(inst.quitted) self.assertTrue(inst.closed)
def test_send_failQuit(self): from email import message_from_string mailer, smtp = self._makeOne() mailer.smtp.fail_on_quit = True try: fromaddr = '*****@*****.**' toaddrs = ('*****@*****.**', '*****@*****.**') headers = 'Headers: headers' body = 'bodybodybody\n-- \nsig\n' msgtext = headers + '\n\n' + body msg = message_from_string(msgtext) mailer.send(fromaddr, toaddrs, msg) self.assertEqual(len(smtp._inst), 1) inst = smtp._inst[0] self.assertEqual(inst.fromaddr, fromaddr) self.assertEqual(inst.toaddrs, toaddrs) self.assertTrue(body.encode('ascii') in inst.msgtext) self.assertTrue(headers.encode('ascii') in inst.msgtext) self.assertTrue(not inst.quitted) self.assertTrue(inst.closed) finally: mailer.smtp.fail_on_quit = False