Yahoo Mail/Gmail 2024 Easy Sender Compliance Guide: Click here

Setting the default from domain in unix mail


If you've ever typed "echo hi | mail user@example.com" from a *nix prompt. then you're familiar with the unix "mail" command, typically part of GNU Mailutils, which, if not already installed on your linux box, you added via "yum install mailutils" or "apt-get install mailutils."

I just did this myself, after repurposing my 12 year old VPS (my oldest active server!) into a dedicated MTA. It's not going to host any websites, it's not going to hold any email list data, it's not going to have a bunch of other random stuff beyond just being a nice and fast and clean Postfix install that is on a server with a dedicated IP address that has 12 years of solid deliverability history. Truly, there's value in a good email reputation history.

Anyway, so I'm setting up occasional alerts. Some more complex than others, but sometimes just something simple that sends output like "echo problem_found | mail user@example.com" and when I test it, my sending from address ends up looking like aiverson@subdomain, not aiverson@subdomain.xnnd.com, with my full domain. I could manually update all my alert outputs to set the from address to what I want, but that's a pain. Why not just set the default to always send mail as the FQDN (fully qualified domain name) instead of just the subdomain? Why not just configure Postfix to always do that when sending off mail? Well, because Postfix is apparently the wrong place to set that. No matter where I confirmed that my FQDN and mailname and myorigin are properly set to the full FQDN, whatever tiny little email I launch via "mail" lacks the FQDN in the from address.

So, I decided to configure mail to set a system-wide default from domain, to ensure it always uses the whole FQDN when sending. Easy to do, but hard to find info about online. Thus, I'll share it with you here, to help the next poor soul trying to figure this out. Here we go.

If you want mail sent with the unix "mail" command to always use a certain from domain, it's actually pretty easy to do. 

  1. Open /etc/mailutils.conf in your favorite editor (nano, of course). If /etc/mailutils.conf is empty because it didn't exist, that's okay. You can create it here and just put what you need into it.
  2. Add this to /etc/mailutils.conf:
    address {
      email-domain subdomain.example.com;
    };
  3. Save /etc/mailutils.conf
    Of course, change subdomain.example.com to your own hostname/FQDN.

And that's it! Now whenever you use the ole "echo hi | mail user@example.com" test to see if a server's alive, or easily punt a status update to an email mailbox, the from address domain will always be subdomain.example.com. Of course, make sure your server is actually called subdomain.example.com, and make sure you've got an SPF record for subdomain.example.com. And it couldn't hurt to set up DKIM, too.

Post a Comment

Comments policy: Al is always right. Kidding, mostly. Be polite, please and thank you.

Previous Post Next Post