I configured command-line email so scripts and cron jobs can send notifications over authenticated SMTP using msmtp as the relay and mailx/mutt as front ends. Reliable script-driven email closed the loop on backups and monitoring without a heavyweight mail server.

Objective & Context

Automation needs a notification channel. This lab routes outbound mail through an authenticated SMTP relay with msmtp, then sends from scripts with mailx and attachments with mutt, complementing the cron and sysadmin labs.

Environment & Prerequisites

  • Linux with mailutils, msmtp, and mutt.
  • SMTP relay credentials (app password, TLS).
  • A test recipient mailbox.

Step-by-Step Execution

1. Configure msmtp relay

# ~/.msmtprc
account default
host smtp.tyfsadik.org
port 587
tls on
auth on
user [email protected]

2. Send from a script

echo "backup completed" | mailx -s "Backup OK" [email protected]

3. Send with an attachment

echo "report attached" | mutt -s "Daily Report" -a report.pdf -- [email protected]
msmtp: mail sent (250 OK)

Validation & Testing

Trigger an email from a cron job and confirm delivery, headers, and attachment integrity. Pass criteria: mail is accepted by the relay (250 OK), arrives in the inbox, and attachments open correctly.

Advanced: Troubleshooting
  • Auth failure: use an app-specific password and confirm TLS on port 587.
  • Marked as spam: ensure SPF/DKIM align with the sending domain.
  • No mail from cron: cron's minimal PATH may miss msmtp; use absolute paths.

Key Results

  • Enabled reliable script-driven email over authenticated SMTP.
  • Delivered job notifications and reports with attachments.
  • Avoided running a full local MTA by relaying through msmtp.
  • Verified deliverability with SPF/DKIM-aligned sending.