def test_get_smtp_server(self): 'Test get_smtp_server' with patch.object(smtplib, 'SMTP') as SMTP: SMTP.return_value = server = Mock() self.assertEqual(get_smtp_server('smtp://*****:*****@localhost:25'), server) SMTP.assert_called_once_with('localhost', 25) server.login.assert_called_once_with('foo', 'bar') with patch.object(smtplib, 'SMTP_SSL') as SMTP: SMTP.return_value = server = Mock() self.assertEqual(get_smtp_server('smtps://localhost:25'), server) SMTP.assert_called_once_with('localhost', 25) with patch.object(smtplib, 'SMTP') as SMTP: SMTP.return_value = server = Mock() self.assertEqual(get_smtp_server('smtp+tls://localhost:25'), server) SMTP.assert_called_once_with('localhost', 25) server.starttls.assert_called_once_with()
def test_get_smtp_server_extra_parameters(self): 'Test get_smtp_server uri extra parameters' with patch.object(smtplib, 'SMTP') as SMTP: SMTP.return_value = server = Mock() params = 'timeout=30&local_hostname=smtp.example.com' self.assertEqual( get_smtp_server('smtp://localhost:25?%s' % params), server) SMTP.assert_called_once_with( 'localhost', 25, timeout=30, local_hostname='smtp.example.com')
def send_all(cls): """ Sends emails with the default SMTP server and marks them as sent. """ server = get_smtp_server() for mail in cls.search([('state', '=', 'outbox')]): mail.send(server) server.quit()
def get_smtp_server(): """ Instanciate, configure and return a SMTP or SMTP_SSL instance from smtplib. :return: A SMTP instance. The quit() method must be call when all the calls to sendmail() have been made. """ from trytond.sendmail import get_smtp_server warnings.warn('get_smtp_server is deprecated use trytond.sendmail', DeprecationWarning) return get_smtp_server()
def test_get_smtp_server(self): "Test get_smtp_server" with patch.object(smtplib, "SMTP") as SMTP: SMTP.return_value = server = Mock() self.assertEqual(get_smtp_server("smtp://*****:*****@localhost:25"), server) SMTP.assert_called_once_with("localhost", 25) server.login.assert_called_once_with("foo", "bar") with patch.object(smtplib, "SMTP_SSL") as SMTP: SMTP.return_value = server = Mock() self.assertEqual(get_smtp_server("smtps://localhost:25"), server) SMTP.assert_called_once_with("localhost", 25) with patch.object(smtplib, "SMTP") as SMTP: SMTP.return_value = server = Mock() self.assertEqual(get_smtp_server("smtp+tls://localhost:25"), server) SMTP.assert_called_once_with("localhost", 25) server.starttls.assert_called_once_with()