feat: allow pass hostname in docker env#6
Conversation
Greptile OverviewGreptile SummaryAdded support for configurable SMTP local hostname via Key changes:
Issues found:
Confidence Score: 2/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant App as Application
participant SMTPClient as SMTPClient
participant Config as dify_config
participant SMTP as smtplib.SMTP/SMTP_SSL
participant Server as SMTP Server
App->>SMTPClient: send(mail)
SMTPClient->>Config: Get SMTP_LOCAL_HOSTNAME
Config-->>SMTPClient: hostname or None
SMTPClient->>SMTPClient: local_host = SMTP_LOCAL_HOSTNAME or ""
alt use_tls=True AND opportunistic_tls=False
SMTPClient->>SMTP: SMTP_SSL(server, port, local_hostname=local_host or None)
else use_tls=True AND opportunistic_tls=True OR use_tls=False
SMTPClient->>SMTP: SMTP(server, port, local_hostname=local_host or None)
end
SMTP-->>SMTPClient: smtp instance
alt use_tls=True AND opportunistic_tls=True
SMTPClient->>SMTP: ehlo(local_host)
SMTP->>Server: EHLO command
Server-->>SMTP: 250 OK
SMTPClient->>SMTP: starttls()
SMTP->>Server: STARTTLS
Server-->>SMTP: 220 Ready
SMTPClient->>SMTP: ehlo(local_host)
SMTP->>Server: EHLO command
Server-->>SMTP: 250 OK
end
alt username and password present
SMTPClient->>SMTP: login(username, password)
SMTP->>Server: AUTH
Server-->>SMTP: 235 Authenticated
end
SMTPClient->>SMTP: sendmail(from, to, message)
SMTP->>Server: MAIL FROM / RCPT TO / DATA
Server-->>SMTP: 250 OK
SMTP-->>SMTPClient: Success
SMTPClient->>SMTP: quit()
SMTP->>Server: QUIT
SMTPClient-->>App: Email sent
|
|
|
||
| assert smtp is not None | ||
| if self.use_tls and self.opportunistic_tls: | ||
| smtp.ehlo(local_host) |
There was a problem hiding this comment.
When SMTP_LOCAL_HOSTNAME is not configured, local_host will be an empty string "". Passing an empty string to ehlo("") sends an invalid/empty hostname in the SMTP EHLO command, which violates SMTP protocol and may cause mail server rejections.
The constructor correctly handles this at line 29 with local_hostname=local_host or None, but the direct ehlo() calls should use the same pattern.
| smtp.ehlo(local_host) | |
| smtp.ehlo(local_host or None) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: api/libs/smtp.py
Line: 34:34
Comment:
When `SMTP_LOCAL_HOSTNAME` is not configured, `local_host` will be an empty string `""`. Passing an empty string to `ehlo("")` sends an invalid/empty hostname in the SMTP EHLO command, which violates SMTP protocol and may cause mail server rejections.
The constructor correctly handles this at line 29 with `local_hostname=local_host or None`, but the direct `ehlo()` calls should use the same pattern.
```suggestion
smtp.ehlo(local_host or None)
```
How can I resolve this? If you propose a fix, please make it concise.| if self.use_tls and self.opportunistic_tls: | ||
| smtp.ehlo(local_host) | ||
| smtp.starttls() | ||
| smtp.ehlo(local_host) |
There was a problem hiding this comment.
Same issue - when SMTP_LOCAL_HOSTNAME is not configured, local_host="" and ehlo("") sends an empty hostname.
| smtp.ehlo(local_host) | |
| smtp.ehlo(local_host or None) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: api/libs/smtp.py
Line: 36:36
Comment:
Same issue - when `SMTP_LOCAL_HOSTNAME` is not configured, `local_host=""` and `ehlo("")` sends an empty hostname.
```suggestion
smtp.ehlo(local_host or None)
```
How can I resolve this? If you propose a fix, please make it concise.| smtp = (smtplib.SMTP_SSL if (self.use_tls and not self.opportunistic_tls) else smtplib.SMTP)( | ||
| self.server, self.port, timeout=10, local_hostname=local_host or None | ||
| ) |
There was a problem hiding this comment.
The ternary expression and class instantiation are combined on one line, making it harder to read and debug. The assertion on line 32 is also unnecessary since the ternary always returns a valid SMTP object.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: api/libs/smtp.py
Line: 28:30
Comment:
The ternary expression and class instantiation are combined on one line, making it harder to read and debug. The assertion on line 32 is also unnecessary since the ternary always returns a valid SMTP object.
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.| self.server, self.port, timeout=10, local_hostname=local_host or None | ||
| ) | ||
|
|
||
| assert smtp is not None |
There was a problem hiding this comment.
This assertion is unnecessary - the ternary on line 28 always returns either SMTP_SSL or SMTP instance, never None.
Prompt To Fix With AI
This is a comment left during a code review.
Path: api/libs/smtp.py
Line: 32:32
Comment:
This assertion is unnecessary - the ternary on line 28 always returns either `SMTP_SSL` or `SMTP` instance, never `None`.
How can I resolve this? If you propose a fix, please make it concise.
Benchmark PR from agentic-review-benchmarks#6