postfix/dovecot: email actually does arrive, but "mail" commands says "no mail" for me (plus from field issue)

Jam Roll asked:

Ubuntu 20.04 LTS on a static IP connection.

I have setup postfix and dovecot to use Maildir/.
I can send messages (although, the reply address on recipient’s end isn’t right) and I can and do receive emails. Oddly, however, when I run the mail command at my terminal, it says No mail for jarett. Everything else is working. All tests show no errors, anywhere. DNS is correctly setup, too. Firewall (both router and computer) are set correctly. I just cannot figure out why the mail doesn’t pick it up (when it has in the past, but…configuration and tweaking messed that up)! I’ve since ironed out all issues, save for this one. To be perfectly forward with you, I am not well versed in this subject, so I admit I am having difficulty asking google this question, hence, this post.

I have setup the mailbox type to be ~/Maildir for both postfix and dovecot. Many searches state there should be an environment variable pointing to this folder, but, initially there was not. Adding "MAIL=~/Maildir/" to .bashrc doesn’t do the trick! So, here is my configuration for both postfix and dovecot:

Contents of /etc/postfix/main.cf:

smtpd_banner=$myhostname ESMTP $mail_name (Ubuntu)
biff=no
append_dot_mydomain=no
readme_directory=no
compatibility_level=2
home_mailbox = Maildir/

# TLS parameters
smtpd_use_tls=yes
smtp_tls_security_level=may
smtp_tls_note_starttls_offer=yes
smtpd_tls_security_level=may
smtpd_tls_cert_file=/etc/letsencrypt/live/night-stand.ca/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/night-stand.ca/privkey.pem
smtpd_tls_auth_only=yes
smtpd_tls_session_cache_database=btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database=btree:${data_directory}/smtp_scache

smtpd_sasl_type=dovecot
smtpd_sasl_path=private/auth
smtpd_sasl_auth_enable=yes
smtpd_sasl_security_options=noanonymous, noplaintext
smtpd_sasl_tls_security_options=noanonymous

smtpd_helo_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        reject_invalid_helo_hostname,
        reject_non_fqdn_helo_hostname
smtpd_recipient_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        reject_non_fqdn_recipient,
        reject_unknown_recipient_domain,
        reject_unlisted_recipient,
        reject_unauth_destination
smtpd_sender_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        reject_non_fqdn_sender,
        reject_unknown_sender_domain
smtpd_relay_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        defer_unauth_destination
smtpd_delay_reject=yes
smtpd_helo_required=yes
smtp_always_send_ehlo=yes
smtpd_timeout=30s
smtp_helo_timeout=15s
smtp_rcpt_timeout=15s
smtpd_recipient_limit=40

alias_maps=hash:/etc/postfix/valias
alias_database=hash:/etc/postfix/valias

myhostname=SITE.COM
mydomain=SITE.COM
mydestination=SITE.COM
mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin=$mydomain

relayhost=
mailbox_size_limit=0
recipient_delimiter=+
disable_vrfy_command=yes
strict_rfc821_envelopes=yes
minimal_backoff_time=180s
maximal_backoff_time=3h

inet_interfaces=all
inet_protocols=ipv4

invalid_hostname_reject_code=550
non_fqdn_reject_code=550
unknown_address_reject_code=550
unknown_client_reject_code=550
unknown_hostname_reject_code=550
unverified_recipient_reject_code=550
unverified_sender_reject_code=550

Contents of /etc/dovecot/conf.d/10-mail.conf:

mail_location = maildir:~/Maildir
mail_privileged_group = mail
passdb {
  driver = passwd-file
  args = username_format=%u /etc/dovecot/users
}

userdb {
  driver = static
  args = uid=vmail gid=vmail home=/var/mail/vhost/%d/%n
}

Oh, perhaps you need to know the hosts file contents and hostname contents
/etc/hosts:

127.0.0.1  localhost
127.0.0.1  mysiteaddress.tld

/etc/hostname:

www

Finally, when I send from the email server to gmail (eg command from terminal: echo "this is the body" | mail -s "test 1" "[email protected]"), gmail says it’s coming from "[email protected]" instead of "[email protected]". What in the world did I do? Should I change hostname to my domain name?

I hope I gave you everything you need, and please don’t rake me over the coals if I missed something, or explained it poorly. I am seeking friendly advice and rather noob with this email server stuff (man, what a rabbit hole).

Sincerly
Jarett

My answer:


First, in order to read your mail, you need to install heirloom-mailx. Only this version of the mail command supports Maildir format mailboxes.

As for the domain name on outgoing mail, this is caused by Debian’s insistence on not following the best practice of naming hosts with their fully qualified domain name. (But don’t do this or various Debianisms will probably break). To work around this, set myorigin= to your base domain name (e.g. example.com, not www.example.com) in /etc/postfix/main.cf.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.