Sending Mail From Servers

By hernil

Email is old, tried and tested. But one thing I never actually sat down and did properly was to configure email sending (smtp) on my server(s).

Turns out it’s not too bad albeit with a few quirks. My example uses Migadu and assumes you’ve created an email address to send from (in my case `alerts@domain.com).

Setup

Start by installing mailutils and ssmtp. On Ubuntu 24.04 that means:

sudo apt install mailutils ssmtp

Configure

/etc/ssmtp/ssmtp.conf

# The user that gets all mail for userids less than 1000. Ifblank, address rewriting is disabled.
root=

mailhub=smtp.migadu.com:465

AuthUser=alerts@domain.com
AuthPass=mypassword

hostname=myhost.domain.com
rewriteDomain=domain.com

# Force TLS
UseTLS=YES

And you’ll want a /etc/ssmtp/revaliases file as well. This file defines what users on the system are allowed to send with the alerts@domain.com address.

root:alerts@domain.com:smtp.migadu.com:465
myusername:alerts@domain.com:smtp.migadu.com:465

In my case I want the root and myusername to be able to send.

Testing

Log into the server with myusername and test it with

echo -e 'Subject: test\n\nTesting ssmtp 123' | sendmail -v recieving@somedomain.com

adapting to an address you can actually recieve from of course.

For reference a successful output looks like this:

[<-] 220 mta1.migadu.com ESMTP
[->] EHLO myhost.domain.com
[<-] 250 CHUNKING
[->] AUTH LOGIN
[<-] 334 VHDkwj3gjWU6
[->] YWxDkwj3gjWi5ubw==
[<-] 334 facR43vcmQ6
[<-] 235 2.7.0 Authentication successful
[->] MAIL FROM:<alerts@domain.com>
[<-] 250 2.1.0 Ok
[->] RCPT TO:<recieving@somedomain.com>
[<-] 250 2.1.5 Ok
[->] DATA
[<-] 354 End data with <CR><LF>.<CR><LF>
[->] Received: by myhost.domain.com (sSMTP sendmail emulation); Wed, 19 Aug 2025 20:46:33 +0200
[->] From: "John Doe" <alerts@domain.com>
[->] Date: Wed, 19 Aug 2025 20:46:33 +0200
[->] Subject: test
[->]
[->] Testing ssmtp 123
[->] .
[<-] 250 2.0.0 Ok: queued as E58CEA499B
[->] QUIT
[<-] 221 2.0.0 Bye

Inspiration

https://www.naut.ca/blog/2025/01/15/zfs-health-notifications-by-email/


Input or feedback to this content? Reply via email!
Related Articles