Skip to content

feat: allow pass hostname in docker env#32

Open
tomerqodo wants to merge 2 commits intocoderabbit_full_base_feat_allow_pass_hostname_in_docker_env_pr6from
coderabbit_full_head_feat_allow_pass_hostname_in_docker_env_pr6
Open

feat: allow pass hostname in docker env#32
tomerqodo wants to merge 2 commits intocoderabbit_full_base_feat_allow_pass_hostname_in_docker_env_pr6from
coderabbit_full_head_feat_allow_pass_hostname_in_docker_env_pr6

Conversation

@tomerqodo
Copy link

@tomerqodo tomerqodo commented Jan 29, 2026

Benchmark PR from agentic-review-benchmarks#6

Summary by CodeRabbit

Release Notes

  • New Features
    • Added configurable SMTP local hostname override. Users can now set a custom local hostname for SMTP HELO/EHLO negotiations via the new SMTP_LOCAL_HOSTNAME environment variable. This resolves connection issues in NAT environments or when default hostnames cause server rejections.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2026

Walkthrough

This PR introduces a configurable SMTP_LOCAL_HOSTNAME parameter to allow overriding the local hostname used in SMTP HELO/EHLO commands. The parameter is added to environment configuration files, the MailConfig schema, the SMTP client initialization logic, and corresponding unit tests.

Changes

Cohort / File(s) Summary
Environment Configuration
api/.env.example, api/tests/integration_tests/.env.example, docker/.env.example, docker/docker-compose.yaml
Added optional SMTP_LOCAL_HOSTNAME environment variable with comments describing its purpose for overriding the SMTP HELO/EHLO hostname.
Mail Configuration Schema
api/configs/feature/__init__.py
Added SMTP_LOCAL_HOSTNAME field to MailConfig as an optional string parameter with default None, allowing override of the local hostname used in SMTP HELO/EHLO commands.
SMTP Client Implementation
api/libs/smtp.py
Refactored SMTP class selection using ternary operator; added local_hostname parameter derived from configuration and passed to SMTP/SMTP_SSL constructor; retained TLS negotiation sequence for opportunistic TLS mode.
Unit Tests
api/tests/unit_tests/libs/test_smtp_client.py, api/tests/unit_tests/tasks/test_mail_send_task.py
Updated SMTP constructor call assertions to expect local_hostname=ANY parameter in addition to existing arguments (host, port, timeout).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A little hostname for SMTP to know,
Behind NAT or firewalls it now can go,
Configuration threads through the code so neat,
With tests updated, the feature's complete! 📧✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is largely incomplete, containing only a benchmark PR reference without addressing required template sections like Summary, Screenshots, and Checklist details. Complete the PR description following the template: add a Summary section explaining the changes and motivation, include relevant Screenshots, and provide detailed Checklist responses.
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding SMTP_LOCAL_HOSTNAME configuration to allow passing hostname in docker environment.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b1c59d and 6facade.

📒 Files selected for processing (8)
  • api/.env.example
  • api/configs/feature/__init__.py
  • api/libs/smtp.py
  • api/tests/integration_tests/.env.example
  • api/tests/unit_tests/libs/test_smtp_client.py
  • api/tests/unit_tests/tasks/test_mail_send_task.py
  • docker/.env.example
  • docker/docker-compose.yaml
🔇 Additional comments (13)
api/.env.example (1)

420-421: Nice addition of SMTP_LOCAL_HOSTNAME to env template.
This documents the new override clearly and keeps defaults safe.

api/tests/integration_tests/.env.example (1)

106-107: Good test-env parity for SMTP_LOCAL_HOSTNAME.

docker/docker-compose.yaml (1)

428-428: LGTM — shared env now exposes SMTP_LOCAL_HOSTNAME.

docker/.env.example (1)

971-972: Clear documentation for SMTP_LOCAL_HOSTNAME in docker env template.

api/tests/unit_tests/libs/test_smtp_client.py (1)

1-1: Tests correctly assert local_hostname is passed to SMTP constructors.

Also applies to: 20-20, 41-41

api/configs/feature/__init__.py (1)

952-956: Config addition looks good and well-documented.

api/tests/unit_tests/tasks/test_mail_send_task.py (4)

12-12: LGTM!

The ANY import is correctly added to support the updated assertions that now include local_hostname=ANY for SMTP constructor verification.


154-154: LGTM!

The assertion correctly reflects the updated SMTP_SSL constructor signature that now includes the local_hostname parameter.


184-184: LGTM!

The assertion correctly reflects the updated SMTP constructor signature for the opportunistic TLS flow.


216-216: LGTM!

The assertion correctly reflects the updated SMTP constructor signature for the non-TLS flow. All three test methods are consistently updated.

api/libs/smtp.py (3)

6-7: LGTM!

The import is correctly added to access the new SMTP_LOCAL_HOSTNAME configuration.


24-25: LGTM!

The type annotation improves code clarity, and the fallback to empty string correctly handles None from the configuration.


27-36: LGTM!

The refactored SMTP construction logic is correct:

  • The ternary expression properly selects SMTP_SSL for implicit TLS and SMTP for STARTTLS or plain connections
  • local_hostname=local_host or None correctly passes None when the hostname is unset, allowing smtplib to use the default FQDN
  • The EHLO/STARTTLS/EHLO sequence for opportunistic TLS is correctly implemented

The assertion on line 32 is technically redundant since the constructor will raise on failure rather than return None, but it serves as a type narrowing hint for static analyzers which is acceptable.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants