Ubuntu 16.04服务器Postfix MTA发送邮件进垃圾箱问题求助
Hey Martin, let's figure out why your Postfix-sent emails are landing in spam instead of the inbox. Since your domain isn't blacklisted and this worked smoothly on another server before, the issue is almost certainly tied to missing authentication records or misconfigured Postfix settings on your current Ubuntu 16.04 box. Let's break this down into actionable steps:
1. Critical Email Authentication Records (SPF, DKIM, DMARC)
These are non-negotiable for modern email delivery—your old server probably had these set up, but your new one might not:
- SPF Record: Add a TXT record to your domain's DNS that explicitly allows your server's IP to send emails on its behalf. Example:
Thev=spf1 ip4:YOUR_SERVER_IP -all-alltells mail servers to reject any emails claiming to be from your domain that don't come from the listed IP. - DKIM Signing: Postfix doesn't enable DKIM by default, so you'll need to set it up with
opendkim:- Install it:
sudo apt-get install opendkim opendkim-tools - Generate DKIM keys for your domain:
sudo opendkim-genkey -d yourdomain.com -s mail - Add the generated public key as a TXT record (
mail._domainkey.yourdomain.com) in your DNS. - Configure Postfix to hook into opendkim by adding these lines to
main.cf:milter_default_action = accept milter_protocol = 6 smtpd_milters = inet:localhost:8891 non_smtpd_milters = inet:localhost:8891
- Install it:
- DMARC Record: Add a TXT record (
_dmarc.yourdomain.com) to enforce authentication checks. A basic example:
This tells receivers to quarantine emails that fail SPF/DKIM checks, and sends you reports about delivery issues.v=DMARC1; p=quarantine; sp=quarantine; rua=mailto:dmarc@yourdomain.com
2. Fix Postfix main.cf Configuration Issues
Let's verify key settings in your /etc/postfix/main.cf—these are common culprits:
myhostname: Must be a valid FQDN (Fully Qualified Domain Name) likemail.yourdomain.com, notlocalhostor a generic server hostname. If it's set incorrectly, receivers will flag your emails as suspicious.mydomain: Set this to your base domain (e.g.,yourdomain.com), not a subdomain.myorigin: Should be set to$mydomainso that your outgoing emails appear to come fromyourdomain.cominstead of a random server name.smtpd_banner: Update it to include your FQDN to avoid generic flags:smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)- TLS Settings: Enable TLS to encrypt outgoing emails—many providers mark unencrypted mail as spam:
If you don't have an SSL cert, grab one for free with Let's Encrypt.smtp_tls_security_level = may smtpd_tls_cert_file = /etc/letsencrypt/live/yourdomain.com/fullchain.pem smtpd_tls_key_file = /etc/letsencrypt/live/yourdomain.com/privkey.pem
3. Clean Up Test Emails & Sender Info
When sending from the command line, avoid red flags:
- Use a valid sender address like
admin@yourdomain.cominstead ofroot@localhostoruser@server-1234. - Keep test email content simple (e.g., "Hi, this is a test email from my Ubuntu server")—avoid spammy keywords, excessive caps, or random links.
4. Test & Debug
- Use
swaksto send a test email and get detailed delivery feedback:sudo apt-get install swaks swaks --to recipient@example.com --from admin@yourdomain.com --server localhost - Check Postfix logs for errors or rejection messages:
Look for lines mentioning "spam", "rejected", or authentication failures.tail -f /var/log/mail.log
Once you've implemented these changes, give DNS records 1-2 hours to propagate, then test again. Chances are, missing SPF/DKIM/DMARC or incorrect hostname settings are the root cause here.
内容的提问来源于stack exchange,提问作者Martin AJ

