33import ssl
44import emails
55from emails .backend .smtp import SMTPBackend
6+ from emails .backend .response import SMTPResponse
67
78sendmail_suite = ports .suite ("suites/sendmail.ports" )
89
@@ -96,7 +97,13 @@ def socket_close(env, socket):
9697
9798@sendmail_suite .placeholder ("sendmail-connect" )
9899def sendmail_connect (env , host , port ):
99- return SMTPBackend (host = host , port = port )
100+ backend = SMTPBackend (host = host , port = port )
101+ return backend
102+
103+ @sendmail_suite .placeholder ("sendmail-connect-with-credentials" )
104+ def sendmail_connect_with_credentials (env , host , port , username , password ):
105+ backend = SMTPBackend (host = host , port = port , user = username , password = password )
106+ return backend
100107
101108@sendmail_suite .placeholder ("sendmail-connect-with-auto-starttls" )
102109def sendmail_connect_with_auto_starttls (env , host , port , automatic_mode ):
@@ -127,11 +134,13 @@ def sendmail_secure_connect_with_timeout(env, host, port, cafile, timeout=None):
127134
128135@sendmail_suite .placeholder ("sendmail-disconnect" )
129136def sendmail_disconnect (env , sender ):
137+ if not isinstance (sender , SMTPBackend ):
138+ return sender
130139 sender .close ()
131140
132141@sendmail_suite .placeholder ("sendmail-connected?" )
133- def sendmail_connected (env , sender ):
134- pass
142+ def sendmail_connected (env , backend ):
143+ return backend . _client is not None and backend . _client . sock is not None
135144
136145
137146#
@@ -158,8 +167,8 @@ def sendmail_success(env, result):
158167 return (not isinstance (result , Exception )) and result .status_code == 250
159168
160169@sendmail_suite .placeholder ("send-error?" )
161- def sendmail_error (env , result ):
162- return isinstance (result , Exception ) or result .status_code != 250
170+ def sendmail_error (env , result : SMTPResponse ):
171+ return isinstance (result , Exception ) or result .status_code != 250 or result . error is not None
163172
164173
165174#
@@ -168,14 +177,14 @@ def sendmail_error(env, result):
168177
169178# they do mitigation for addresses but detection for other fields
170179
171- sendmail_suite .run (#only_capabilities=("root.send-message",),
172- exclude_capabilities = (
173- "root.connection" ,
174- "root.crlf-injection-detection.detection" ,
175- "root.8bitmime" ,
176- "root.smtputf8.explicit-options" ),
177- expected_failures = (
178- # The library should problably automatically detect whether smtputf8 is required
179- "test_international_sender_mailbox_in_send-message_with_SMTPUTF8_support" ,
180- "test_international_recipient_mailbox_in_send-message_with_SMTPUTF8_support" ,
181- "test_Send_a_message_with_empty_recipient" ,))
180+ sendmail_suite .run (
181+ exclude_capabilities = (
182+ "root.connection.eager- connection" ,
183+ "root.crlf-injection-detection.detection" ,
184+ "root.8bitmime" ,
185+ "root.smtputf8.explicit-options" ),
186+ expected_failures = (
187+ # The library should problably automatically detect whether smtputf8 is required
188+ "test_international_sender_mailbox_in_send-message_with_SMTPUTF8_support" ,
189+ "test_international_recipient_mailbox_in_send-message_with_SMTPUTF8_support" ,
190+ "test_Send_a_message_with_empty_recipient" ,))
0 commit comments