Skip to content

feat: allow pass hostname in docker env#6

Open
tomerqodo wants to merge 2 commits into
copilot_full_base_feat_allow_pass_hostname_in_docker_env_pr6from
copilot_full_head_feat_allow_pass_hostname_in_docker_env_pr6
Open

feat: allow pass hostname in docker env#6
tomerqodo wants to merge 2 commits into
copilot_full_base_feat_allow_pass_hostname_in_docker_env_pr6from
copilot_full_head_feat_allow_pass_hostname_in_docker_env_pr6

Conversation

@tomerqodo

Copy link
Copy Markdown

Benchmark PR from agentic-review-benchmarks#6

Copilot AI review requested due to automatic review settings January 25, 2026 22:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for configuring a custom local hostname for SMTP HELO/EHLO commands through a new SMTP_LOCAL_HOSTNAME environment variable. This is useful for deployments behind NAT or when the default hostname causes SMTP server rejections.

Changes:

  • Added SMTP_LOCAL_HOSTNAME configuration field to support custom hostname in SMTP HELO/EHLO
  • Refactored SMTP client to use ternary operator for TLS mode selection and pass local_hostname parameter
  • Updated tests to accommodate the new local_hostname parameter using ANY matcher

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
docker/docker-compose.yaml Added SMTP_LOCAL_HOSTNAME environment variable mapping
docker/.env.example Added SMTP_LOCAL_HOSTNAME configuration with documentation
api/.env.example Added SMTP_LOCAL_HOSTNAME configuration with documentation
api/tests/integration_tests/.env.example Added SMTP_LOCAL_HOSTNAME configuration with documentation
api/configs/feature/init.py Added SMTP_LOCAL_HOSTNAME field to MailConfig with description
api/libs/smtp.py Refactored SMTP client to use local_hostname parameter and simplified TLS mode handling
api/tests/unit_tests/tasks/test_mail_send_task.py Updated test assertions to use ANY matcher for local_hostname parameter
api/tests/unit_tests/libs/test_smtp_client.py Updated test assertions to use ANY matcher for local_hostname parameter

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

client.send(_mail())

mock_smtp_cls.assert_called_once_with("smtp.example.com", 587, timeout=10)
mock_smtp_cls.assert_called_once_with("smtp.example.com", 587, timeout=10, local_hostname=ANY)

Copilot AI Jan 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test changes only verify that local_hostname parameter is passed to SMTP constructors using ANY matcher, but don't actually test the new SMTP_LOCAL_HOSTNAME configuration feature. Consider adding tests that:

  1. Verify that when SMTP_LOCAL_HOSTNAME is configured (e.g., "custom.hostname.com"), it's correctly passed to smtplib.SMTP/SMTP_SSL constructors and ehlo() calls
  2. Verify that when SMTP_LOCAL_HOSTNAME is None/empty, the default behavior (None) is used

This would ensure the feature works as intended and catches regressions.

Copilot uses AI. Check for mistakes.
Comment thread api/libs/smtp.py
self.server, self.port, timeout=10, local_hostname=local_host or None
)

assert smtp is not None

Copilot AI Jan 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assert statement on line 32 is unnecessary. The ternary expression on lines 28-30 always returns either an SMTP or SMTP_SSL instance, so smtp can never be None at this point. This assertion serves no functional purpose and should be removed.

Suggested change
assert smtp is not None

Copilot uses AI. Check for mistakes.

# Assert
mock_smtp_ssl.assert_called_once_with("smtp.example.com", 465, timeout=10)
mock_smtp_ssl.assert_called_once_with("smtp.example.com", 465, timeout=10, local_hostname=ANY)

Copilot AI Jan 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test changes only verify that local_hostname parameter is passed to SMTP constructors using ANY matcher, but don't actually test the new SMTP_LOCAL_HOSTNAME configuration feature. Consider adding tests that:

  1. Verify that when SMTP_LOCAL_HOSTNAME is configured (e.g., "custom.hostname.com"), it's correctly passed to smtplib.SMTP/SMTP_SSL constructors and ehlo() calls
  2. Verify that when SMTP_LOCAL_HOSTNAME is None/empty, the default behavior (None) is used

This would ensure the feature works as intended and catches regressions.

Copilot uses AI. Check for mistakes.
Comment thread api/libs/smtp.py
Comment on lines +34 to +36
smtp.ehlo(local_host)
smtp.starttls()
smtp.ehlo(local_host)

Copilot AI Jan 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking change in EHLO hostname behavior. The original code called ehlo(self.server) which used the SMTP server address for the HELO/EHLO command. The new code calls ehlo(local_host), where local_host is "" when SMTP_LOCAL_HOSTNAME is not configured (line 25).

When ehlo("") is called, Python's smtplib uses socket.getfqdn() to determine the local machine's fully qualified domain name.

This changes the default behavior for existing users:

  • Original: ehlo("smtp.example.com") - identifies as the SMTP server address
  • New: ehlo("") → uses socket.getfqdn() - identifies as the local machine's FQDN

This is a breaking change that could affect SMTP delivery. Some SMTP servers may have whitelisted the old behavior or could reject connections from hosts identifying with different FQDNs. To maintain backward compatibility while adding the new feature, consider using the server address as fallback: local_host = dify_config.SMTP_LOCAL_HOSTNAME or self.server

Copilot uses AI. Check for mistakes.
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.

3 participants