Skip to main content

Install sendmail service on Debian

Overview

This guide explains how to set up authenticated email sending from the command line on Debian-based systems (including Proxmox Backup Server) using msmtp (a lightweight SMTP client) and s-nail (a mailx-compatible utility). This is ideal for system notifications, backup/email scripts, and environments with DMARC/SPF filtering where authenticated sending is required.

1. Install Required Packages

apt update
apt install -y msmtp s-nail  

2. Configure msmtp

  1. Create/Edit the global configuration file:
    nano /etc/msmtprc
  2. Example /etc/msmtprc:
    
    defaults
    auth           on
    tls            on
    tls_trust_file /etc/ssl/certs/ca-certificates.crt
    logfile        /var/log/msmtp.log
    syslog         LOG_MAIL
    
    account        default
    host           mail.hosting.de
    port           587
    from           admin@simmy.org
    user           admin@simmy.org
    password       
          
    • Use only plain ASCII spaces (no tabs or Unicode spaces).
    • Replace <your-mail-password> with your actual password.
    • Important: "from" and "user" should match your authenticated email address for DMARC/SPF.
  3. Set strict permissions:
    chmod 600 /etc/msmtprc

3. Configure s-nail or mailx to use msmtp

Add the following line to your /etc/s-nail.rc (system-wide) or ~/.mailrc (per user):

set mta=/usr/bin/msmtp

4. Send a Test Email

Use the mail command to test sending:

echo "This is the body" | mail -s "Test Subject" recipient@example.com  

On success, no output is shown. Check /var/log/msmtp.log or /var/log/mail.log (if syslog is enabled) for debug info if not delivered.

5. Troubleshooting

  • If mail arrives in Junk/Spam, create a filter at your destination mailbox to whitelist the sender or move to Inbox.
  • If you see an error like “account default was already