This commit is contained in:
Adrià Casajús
2025-07-30 15:49:37 +02:00
committed by Adrià Casajús
parent 3c8b5c8f5b
commit 6dc6264d5d
3 changed files with 12 additions and 5 deletions
+4 -1
View File
@@ -200,7 +200,7 @@ class MailSender:
elapsed = time.time() - start
LOG.d(
f"Getting a smtp connection to {server_host} takes seconds {elapsed:.3} seconds"
f"Getting a smtp connection to {server_host}:{server_port} takes seconds {elapsed:.3} seconds"
)
newrelic.agent.record_custom_metric("Custom/smtp_connection_time", elapsed)
@@ -221,6 +221,9 @@ class MailSender:
send_request.mail_options,
send_request.rcpt_options,
)
LOG.d(
f"Email sent using {server_host}:{server_port} from {send_request.envelope_from} to {send_request.envelope_to}"
)
return True
+1
View File
@@ -148,6 +148,7 @@ def test_disabled_user_with_secondary_mailbox_prevents_email_from_being_used_as_
def test_mx_invalid_ip():
ForbiddenMxIp.filter().delete()
invalid_mx_ip = "12.2.23.23"
valid_mx_ip = "1.1.1.1"
ForbiddenMxIp.create(ip=invalid_mx_ip, flush=True)
+7 -4
View File
@@ -106,10 +106,10 @@ def compare_send_requests(expected: SendRequest, request: SendRequest):
)
def test_mail_sender_save_unsent_to_disk(server_fn):
original_postfix_server = config.POSTFIX_SERVERS
config.POSTFIX_SERVERS = ["localhost"]
port_closed = closed_dummy_server()
config.POSTFIX_SERVERS = [f"localhost:{port_closed}"]
config.NOT_SEND_EMAIL = False
config.POSTFIX_SUBMISSION_TLS = False
config.POSTFIX_TIMEOUT = 6000
config.POSTFIX_PORT = server_fn()
try:
with tempfile.TemporaryDirectory() as temp_dir:
@@ -156,13 +156,15 @@ def test_mail_sender_try_backup_postfix():
assert mail_sender.send(send_request, 0)
finally:
config.POSTFIX_SERVERS = original_postfix_server
config.POSTFIX_BACKUP_SERVERS = []
config.NOT_SEND_EMAIL = True
@mail_sender.store_emails_test_decorator
def test_send_unsent_email_from_fs():
original_postfix_server = config.POSTFIX_SERVERS
config.POSTFIX_SERVERS = ["localhost"]
port_closed = closed_dummy_server()
config.POSTFIX_SERVERS = [f"localhost:{port_closed}"]
config.NOT_SEND_EMAIL = False
with tempfile.TemporaryDirectory() as temp_dir:
try:
@@ -188,7 +190,8 @@ def test_send_unsent_email_from_fs():
@mail_sender.store_emails_test_decorator
def test_failed_resend_does_not_delete_file():
original_postfix_server = config.POSTFIX_SERVERS
config.POSTFIX_SERVERS = ["localhost"]
port_closed = closed_dummy_server()
config.POSTFIX_SERVERS = [f"localhost:{port_closed}"]
config.NOT_SEND_EMAIL = False
try:
with tempfile.TemporaryDirectory() as temp_dir: