Step-by-Step Guide: Configure s-nail with msmtp and Resend SMTP

por | 1 mayo, 2025

This guide walks you through installing s-nail as a mail client and configuring msmtp to send emails using the Resend SMTP service. It also replaces conflicting tools (like GNU mailutils), applies system aliases, and includes instructions for managing AppArmor on a Debian-based system (e.g., Ubuntu 22.04 or later).

Tested on: Linux linux-mailhost 6.8.0-1022-oracle x86_64 GNU/Linux


🛠 Prerequisites

  • Debian-based system (e.g., Ubuntu)
  • sudo or root access
  • Valid SMTP credentials from Resend
  • AppArmor enabled (optional for security)

📤 Step 1: Remove Conflicting Mail Packages

sudo apt remove --purge mailutils
sudo apt autoremove
sudo apt autoclean

Verify that mail and mailx are gone:

mail --version
mailx --version

If still present, locate and remove:

dpkg -S /usr/bin/mail
dpkg -S /usr/bin/mailx
sudo apt remove bsd-mailx


📥 Step 2: Install s-nail

sudo apt update
sudo apt install s-nail

Verify:

s-nail --version

Expected output: something like s-nail 14.9.24


📦 Step 3: Install and Configure msmtp (for Resend)

sudo apt install msmtp

Check version:

msmtp --version

✅ Step 4: Ensure SSL Certificate Store Is Installed

To use tls_trust_file properly in msmtp, ensure the system has CA certificates:

sudo apt install ca-certificates
sudo update-ca-certificates

This ensures the file /etc/ssl/certs/ca-certificates.crt exists and is up to date.


📄 Step 5: Create msmtp Config for Resend

Edit your user configuration file:

nano ~/.msmtprc

Paste this (replace with real credentials):

# Global configuration
defaults
auth           on
tls            on
tls_starttls   off
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile        ~/.msmtp.log

# Resend SMTP
account        resend
host           smtp.resend.com
port           465
from           [email protected]
user           resend
password       your_resend_password_or_api_key

account default : resend

⚠️ Never share your .msmtprc or store it with world-readable permissions.

Set correct file permissions:

chmod 600 ~/.msmtprc

🧪 Step 6: Test msmtp

echo -e "To: [email protected]\nFrom: [email protected]\nSubject: Test Email\n\nTest body" | msmtp -t

Check log:

cat ~/.msmtp.log

📧 Step 7: Configure s-nail

Edit your s-nail config:

nano ~/.mailrc

Add the following:

set sendmail="/usr/bin/msmtp"
set from="[email protected]"

🧪 Step 8: Test s-nail

echo "Hello from s-nail + msmtp + Resend!" | s-nail -s "Hello" [email protected]

🔁 Step 9: Set Aliases for Compatibility

echo 'alias mail="s-nail"' >> ~/.bashrc
echo 'alias mailx="s-nail"' >> ~/.bashrc
source ~/.bashrc

Test:

echo "Alias test" | mail -s "Mail alias working" [email protected]

🔐 Step 10: AppArmor Configuration (If Needed)

Check if AppArmor restricts s-nail or msmtp:

sudo aa-status | grep -E 's-nail|msmtp'
sudo tail -f /var/log/syslog | grep -i apparmor

If necessary, create/edit AppArmor profile:

sudo nano /etc/apparmor.d/usr.bin.s-nail

Add rules:

/usr/bin/msmtp rix,
/home/your_username/.msmtprc r,
/home/your_username/.msmtp.log rw,
/etc/msmtprc r,

Reload:

sudo apparmor_parser -r /etc/apparmor.d/usr.bin.s-nail

✅ Final Verification

Confirm mail and mailx are gone:

dpkg -l | grep -E 'mail|mailx'
mail --version
mailx --version

Confirm s-nail and msmtp send emails correctly:

echo "Final check" | s-nail -s "Done" [email protected]

🧰 Troubleshooting

  • msmtp not sending: Enable debugging: debug Then run: msmtp --debug [email protected] cat ~/.msmtp.log
  • Permission issues: chmod 755 /usr/bin/msmtp chmod 600 ~/.msmtprc
  • Disable AppArmor (not recommended permanently): sudo aa-disable /usr/bin/s-nail sudo aa-disable /usr/bin/msmtp