PR 400 Sending Through A Relay Without A Login - edmozley/freeitsm GitHub Wiki
๐ค PR #400 Basic IMAP mailboxes could not send through a relay that wants no login
GitHub PR #400, found and built by @Dr4inder ยท Tickets โ Mailboxes ยท in 5.7.0 (#3012)
What you saw
You point a Basic IMAP / SMTP mailbox's SMTP server at an internal relay that lets the FreeITSM server send because of where it is, not who it logs in as. Mail is collected perfectly, but every reply, workflow email and notification fails with something like:
SMTP sign-in failed: 504 5.7.4 Unrecognized authentication type
Exchange receive connectors set up for anonymous relay, Postfix relays restricted by mynetworks, and most on-premises smarthosts behave this way. There was nothing on the mailbox to tell FreeITSM not to log in. This wiki even said so: "A relay that wants no authentication at all is not configurable here."
What was wrong
imapSmtpSend() in includes/mailbox_imap.php, the one sender behind every email a Basic IMAP mailbox sends, always logged in. If the mailbox had no separate SMTP login it fell back to the IMAP one, and a Basic IMAP mailbox always has an IMAP login. So it always sent AUTH LOGIN, and a relay that refuses AUTH refused the email.
The fix
@Dr4inder added a mailbox setting, Authenticate with the SMTP server, stored in the new column target_mailboxes.smtp_auth_enabled. It defaults to on, so every existing mailbox sends exactly as before. Turned off, the login step is skipped:
// AUTH LOGIN (username + password, each base64).
if (($mailbox['smtp_auth_enabled'] ?? true) && $user !== '') {
try {
imapSmtpCommand($fp, 'AUTH LOGIN', [334]);
imapSmtpCommand($fp, base64_encode($user), [334]);
imapSmtpCommand($fp, base64_encode($pass), [235]);
} catch (SmtpReplyException $e) {
throw new Exception('SMTP sign-in failed: ' . $e->reply);
}
}
What stays the same with it off:
- IMAP still logs in to collect mail and, if you use it, to file a copy in Sent.
- Encryption (SSL / STARTTLS) is still its own setting, so you can relay without a login and still encrypt.
- Saved logins are kept. Turn authentication back on and the separate SMTP username and password are still there.
- The Test button uses the setting as it is on screen, before you save.
The safety check it kept
The Test button already refused to reuse a saved password for a server it was not saved for, so a changed SMTP server could never be handed your stored login. With authentication off, the SMTP server never receives a password, so the PR moves that check to the place a password does still go: the saved IMAP password is reused only while the IMAP server and username are unchanged. From includes/mailbox_send.php:
// Without SMTP authentication the IMAP password is only used to file Sent.
$imapPasswordHostUnchanged = $smtpAuth ? $serverUnchanged
: ($stored !== null && $same($stored['imap_server'] ?? '', $mb['imap_server'] ?? ''));
I checked this specifically before merging. It is the part of the PR that could have leaked a password if it had been got wrong.
Upgrading
The column is added by System โ Database Verification. Before that has run, mailboxes still list and save normally, but trying to turn authentication off is refused with a message telling you to run it, rather than silently ignored. An older browser tab that does not send the setting at all leaves the saved choice alone.
What I added on top
- The setting's label and help text in the eight other languages FreeITSM ships at 100%.
- A merge fix: the PR saved
lang/en/tickets.phpwith different line endings from the rest of the project, which made Git see the whole file as changed. I rebuilt it from the current file plus the PR's two new lines, so its history stays readable. - A Feature Bingo card, Send through a relay without a login, and a line in the README.
๐ Files
| File | Change |
|---|---|
๐ฃ includes/mailbox_imap.php |
imapSmtpSend() skips AUTH LOGIN when the setting is off |
๐ฃ includes/mailbox_send.php |
mailboxTestResolve(): the setting on Test, and the password-reuse check above |
๐ก api/tickets/save_mailbox.php, get_mailboxes.php |
Save and return smtp_auth_enabled; refuse turning it off before Database Verification |
๐ก tickets/settings/index.php |
The switch; the SMTP login fields hide while it is off |
โช includes/db_verify_schema.php, database/freeitsm.sql |
smtp_auth_enabled TINYINT(1) NOT NULL DEFAULT 1 |
โช lang/*/tickets.php |
smtp_auth_enabled, smtp_auth_help |
๐ข tests/mailbox-smtp-auth.php, mailbox-smtp-auth-ui.php, mailbox-send-test.php, mailbox-sent-copy.php |
12 + 20 + 48 + 27 checks |
How it was verified
All four tests pass on a test install after merging. mailbox-sent-copy.php runs real SMTP and IMAP conversations against local stand-in servers, including a relay that answers every AUTH with 504: with the setting off the email is delivered and filed in Sent, and with it on the send fails exactly as before. mailbox-smtp-auth.php saves real mailboxes through the endpoint: the default is on, turning it off is saved and returned, the logins survive, and a malformed value is refused.
What this means for you
Update to 5.7.0 and run System โ Database Verification. Then, for a mailbox that sends through a relay which trusts your server, open it under Tickets โ Settings โ Mailboxes, turn off Authenticate with the SMTP server, and click Test. Leave it on for everything else - a provider that expects a login (Fastmail, cPanel hosting, Microsoft 365 SMTP) will refuse mail without one.
Related: Basic IMAP mailboxes ยท Basic IMAP client - Developer Guide