Skip to content

RouterOS 7.22: e-mail send fails from script with socket error / invalid BODY when using multiline body and attachment array #79

Description

@realfeigling

Hi,

on RouterOS 7.22.2 I can send backup e-mails manually from terminal, including multiline body and two attachments, but the BackupAndUpdate script fails when sending the same data from script.

Working manual command pattern:

:local NL "\r\n"
:local body ("System backups have been successfully created and attached to this email." . $NL . $NL . "Device information:" . $NL . "RouterOS version: v7.22.2 (stable)")
/tool e-mail send to=user@example.com subject="manual-full-body-two-files" body=$body file="backup.backup,backup.rsc"

Observed script errors:

Error sending e-mail <...>: socket error

Earlier multiline body tests also showed:

invalid BODY

Findings:

  • Multiline body works when built with CRLF ("\r\n"), but fails or is unstable with "\n".
  • Sending two attachments works when file= receives a comma-separated string:
    backup.backup,backup.rsc
  • Sending from script is unstable when attachments are passed as RouterOS array:
    {$backupFileSys;$backupFileConfig}
  • Dynamic subjects containing backticks around identity names may also trigger send instability on 7.22.
  • Backup files should only be deleted after /tool e-mail get last-status is confirmed as succeeded.

Suggested fix:

  • Build mail body with CRLF.
  • Return attachment list as comma-separated string instead of array.
  • Avoid backticks or special formatting in mail subject.
  • Delete backup files only after confirmed successful delivery.

Environment:

  • RouterOS: 7.22.2 stable
  • Script mode: backup
  • E-mail sending from terminal works
  • E-mail sending from script fails with same attachments unless adjusted as above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions