📑 ???
???????????????????/h2>
DMARC??omain-based Message Authentication, Reporting and Conformance??? RFC 7489 ??????????????????p=reject ????????? DMARC ???????????? Google??icrosoft??ahoo??????????? SPF ??DKIM ????????align ?????????????/p>
???????????/p>
"???????????Gmail ??????????????????? 'The message from xxx@gmail.com was rejected because the domain example.com has a DMARC reject policy.' ???????????????????
??????????????????????????SPF/DKIM ??????????????????????br>????????????????????/p>
- ??????????????Authentication-Results ??/li>
- ??? DMARC DNS ?????????????????????
- ??? rua ????????? SPF/DKIM ??????
- ?????? SPF ??DKIM ??????
- ??????????????????
- ?????????????????????/li>
????uthentication-Results ????????/h2>
2.1 ????????/h3>
Authentication-Results ??? RFC 8601 ????????MTA??? Gmail???????????????????????????????????????????strong>????????/strong>??/p>
Authentication-Results: mx.google.com;
dkim=pass header.i=@example.com header.s=selector1;
spf=pass (google.com: domain of newsletter@example.com designates 203.0.113.5 as permitted sender) smtp.mailfrom=newsletter@example.com;
dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=example.com
????????/p>
| ??? | ??? | ?????/th> | ?????/th> |
|---|---|---|---|
dkim= | DKM ????????? | pass | fail/neutral/none |
spf= | SPF ????????FC 7208??/td> | pass | fail/softfail/neutral/none |
dmarc= | DMARC ???????/td> | pass | fail |
header.from= | RFC 5322.From ??? | DMARC ???????????/td> | |
2.2 ?????????????????/h3>
?????????????????????????????strong>???????/strong>???????????????????????/strong>??/p>
??????????????????????????? Google Admin Toolbox Messageheader ????????/p>
????????? DNS ?????????????? ???????????? Gmail ???????? Google Postmaster Tools ?????? DMARC ????????????????Google ?????????????????? RFC 7489 Section 7 ?????XML ???????????????????? Google??icrosoft??ahoo?????DMARC ????????? ?????????????parsedmarc ???????????rua ?????/p>
??rua ????????? SPF fail ??????????SPF ????????strong>?????? SPF ????????/p>
DKIM ???????????????????????NS ????????????????????/p>
?????????????????? Salesforce??endesk??ailchimp ????????? SPF include ??DKIM ????????? rua ?????????????????????????????????????????????????/p>
????????? DMARC ?????????????????????????????? ?????????????????/strong>???????????????????????????????????/p>
???????????DMARC ?????????????????????????????Google???????????????????????? DMARC ?????????????????????????/p>
??????????????????????????????????????????????/p>
DMARC ?????? ??????"???????rganizational Domain?????????????????? DMARC ????????/p>
???????????? ??? ?????????????????????????????Gmail??utlook.com????????????????????????????????? DMARC ??????????????????????????????????????????????????????????????????SPF/DKIM ????????????????????? DMARC ?????/p>
ztpop.net 知识库编辑. "DMARC p=reject ???????????????????????" ztpop.net 知识库. 本站技术文章采用 CC-BY 4.0 许可,可自由引用,仅需标注来源 ztpop.net。# Gmail ?????????????????
Authentication-Results: mx.google.com;
dkim=**fail** header.i=@partner-domain.com header.s=dkim1024;
spf=**fail** (google.com: domain of sender@partner-domain.com does not designate 198.51.100.20 as permitted sender) smtp.mailfrom=sender@partner-domain.com;
dmarc=**fail** (p=REJECT sp=REJECT dis=QUARANTINE) header.from=partner-domain.com
# ????????# 1. dkim=fail ??????????? DKIM ?????????
# 2. spf=fail ??????????? SPF ????????? IP
# 3. dmarc=fail ?????????????? DMARC ??????
# 4. dis=QUARANTINE ??Gmail ????????????????????p=REJECT??? Gmail ???????????????2.3 ??? Gmail ???????/h3>
# ????????????
# https://toolbox.googleapps.com/apps/messageheader/
#
# ??????????????????????????? "???" ??????
# - ???????????? SPF/DKIM/DMARC ???
# - ??????????????# - ?????????
# ??? DMARC ???
dig TXT _dmarc.partner-domain.com +short
# ?????v=DMARC1; p=reject; sp=reject; rua=mailto:dmarc@partner-domain.com"
# ??? SPF ???
dig TXT partner-domain.com +short
# ?????????????IP ???????
# ??? DKIM ???
dig TXT dkim1024._domainkey.partner-domain.com +short????MARC DNS ?????????
3.1 Google Postmaster Tools (GPT) ??????
1. ??? https://postmaster.google.com
2. ??Gmail ??????????????????
3. ???????????DNS ???
4. ??? "???" (Authentication) ????? ?????PF ?????/ DKIM ?????/ DMARC ?????/ ???????????5. ??? "??????? ????? ???????????? / SMTP ????????/ ?????
# ?????????
# DMARC ?????< 95% ?????????# SPF ?????< 90% ??SPF ?????????
# DKIM ?????< 85% ??DKIM ???????????MTA ???
3.2 ????????????
??? ?????/th> ??? Google Check MX Google ???????SPF??KIM??MARC ?????? dmarctest.com PowerDMARC ????????????????? DMARC ?????? mail-tester.com ??? ??????????????SPF/DKIM/DMARC??/td> DMARC Analyzer Red Sift rua ????????+ ??????????????? dmarcian checker dmarcian DMARC DNS ?????? # ??? dmarctest.com API ??????????????????? API key??curl -X POST https://api.dmarctest.com/v1/send-test \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"from_address": "test@example.com", "to_address": "check@dmarctest.com"}'????ua ?????????
4.1 DMARC rua ??????
rua URI????????XML ???????????????????????????
4.2 ??? parsedmarc ??????
# ??? parsedmarc??ython 3.9+??pip install parsedmarc
# ??? parsedmarc
cat > /etc/parsedmarc/config.ini << 'INI'
[general]
save_aggregate = True
save_forensic = True
[elasticsearch]
hosts = localhost:9200
# ???????? ELK ????????
[imap]
host = imap.example.com
user = dmarc-reports@example.com
password = YOUR_SECURE_PASSWORD
watch = True
report_folder = INBOX/dmarc-reports
archive_folder = INBOX/dmarc-reports/archive
INI
# ????????????
parsedmarc -c /etc/parsedmarc/config.ini --no-recurse
# ????????????
cat > /usr/local/bin/analyze-dmarc-reports.py << 'PYTHON'
#!/usr/bin/env python3
"""
??? parsedmarc CSV ????????DMARC ???????? Top 10 ??? IP ?????"""
import csv
import sys
from collections import Counter
failures_per_ip = Counter()
failures_per_domain = Counter()
reader = csv.DictReader(sys.stdin)
for row in reader:
dmarc_disposition = row.get('disposition', '')
if dmarc_disposition in ('reject', 'quarantine'):
failures_per_ip[row.get('source_ip_address', 'unknown')] += 1
failures_per_domain[row.get('header_from', 'unknown')] += 1
print("=== DMARC ???????? Top 10 ??? IP ===")
for ip, count in failures_per_ip.most_common(10):
print(f" {ip}: {count} ?????)
print("\n=== DMARC ???????? Top 10 Header From ??? ===")
for domain, count in failures_per_domain.most_common(10):
print(f" {domain}: {count} ?????)
PYTHON
chmod 755 /usr/local/bin/analyze-dmarc-reports.py
# ??? CSV ?????parsedmarc -c /etc/parsedmarc/config.ini \
--output-format csv \
--output-file - 2>/dev/null | \
/usr/local/bin/analyze-dmarc-reports.py4.3 ??????????????????
?????? ?????? ??? ??????
SPF fail + DKIM pass
DKIM=pass, SPF=fail, DMARC=pass ??fail
??? IP ?????? SPF ?????????????????DKIM ???
??? SPF ????????IP?????? DKIM ?????? d= ??header.From ????/td>
SPF pass + DKIM fail
SPF=pass, DKIM=fail, DMARC=pass ??fail
????????? mailing list??????????????? DKIM ??????
??? ARC??FC 8617????????DKIM ??? mta ???
l= ???????????? p=quarantine
?????? fail
SPF=fail, DKIM=fail
??????????????????
?????????????????? SPF/DKIM/DMARC
?????????
?????????
sub.example.com??? SPF/DKIM ??????
????????????????? SPF??????
sp= ???????PF/DKIM ??????
5.1 SPF ??????
# SPF ????????DNS ??????
dig TXT example.com +short
# ??? SPF ??? include ???????????????
dig TXT example.com +short | grep -oP 'include:\S+' | wc -l
# ???????????????? include ??DNS ??????
# ??? SPF ???????? spf-tools??pip install spf-tools
spf-tools check example.com
# ??? openspf.org ??SPF ?????# https://www.kitterman.com/spf/validate.htmlcat > /usr/local/bin/spf-debug.sh << 'SH'
#!/bin/bash
# SPF ???????????IP ?????SPF ??????
if [ -z "$1" ] || [ -z "$2" ]; then
echo "???: $0 ??> 5.2 DKIM ??????
# ?????? DKIM ???
cat > /tmp/test-dkim.sh << 'SH'
#!/bin/bash
# ??? opendkim ????????DKIM ???
opendkim-testmsg -d example.com -D /tmp/dkim_keys < /tmp/email.eml
# ?????rspamc ??DKIM ???
rspamc -h localhost:11334 symbols < /tmp/email.eml
# ??? DKIM ????????grep -i 'DKIM-Signature' /tmp/email.eml
# ????DKIM ????????dig TXT 20260101._domainkey.example.com +short
# ??????: "v=DKIM1; h=sha256; k=rsa; p=MIGfMA0G..."
SH
# ?????DKIM ??????
cat > /usr/local/bin/dkim-verify-mail.sh << 'SH'
#!/bin/bash
# ??????????????DKIM ???
if [ ! -f "$1" ]; then
echo "???: $0 ?????>"
exit 1
fi
echo "=== DKIM ?????? ==="
echo ""
echo "--- ?????? DKIM-Signature ??? ---"
grep -i '^DKIM-Signature' "$1" | head -3
echo ""
echo "--- ??? opendkim ??? ---"
opendkim-testmsg "$1" 2>&1
result=$?
if [ "$result" -eq 0 ]; then
echo "??DKIM ?????????"
else
echo "??DKIM ????????? (exit code: $result)"
fi
echo ""
echo "--- ??? rspamd DKIM ??? ---"
if command -v rspamc &>/dev/null; then
rspamc -h localhost:11334 symbols < "$1" 2>&1 | grep -i dkim
fi
SH
chmod 755 /usr/local/bin/dkim-verify-mail.sh???????????????????/h2>
6.1 ??????????????????
??? SPF include DKIM ???????? Mailchimp include:servers.mcsv.netk1._domainkeySalesforce include:_spf.salesforce.comsalesforce._domainkeyZendesk include:mail.zendesk.comzendesk._domainkeySendGrid include:sendgrid.netsg._domainkey?????????Mailgun include:mailgun.orgmg._domainkeyAmazon SES include:amazonses.comamazonses._domainkey6.2 ???????????/h3>
newsletter.example.com????????sp=quarantine ?????????# ????????????????SPF/DKIM
# ??????????????SPF ?????DKIM ??????
# ????????? DMARC ??pct ?????????
# ??DMARC ????????v=DMARC1; p=reject; sp=reject; pct=50; rua=mailto:dmarc@example.com
# ?????50% ???????????????????????????????? 100%
# ?????????????????????
# ?????MARC ??????????????????
# ????????????????????????????????6.3 RFC ??????"????????
# ????????? DMARC ????????????????????dig TXT _dmarc.outlook.com +short
# ??? Microsoft ??DMARC ???????????DMARC ???????????
# ????????Gmail?????? Google ??????
# https://support.google.com/mail/contact/forms/recipientfeedback
# ??????????????????????? 1-2 ??/code>???????????????????/h2>
7.1 ??????????????/h3>
sp=??ubdomain policy???????????????????FC 7489 Section 6.3 ?????? sp= ????????????????????p= ???# ??? A: sp=reject ??p=reject ???
_dmarc.example.com. IN TXT "v=DMARC1; p=reject; sp=reject; ..."
# ??????*.example.com ??????????? SPF/DKIM ???
# ??? B: ?????????
_dmarc.example.com. IN TXT "v=DMARC1; p=reject; sp=quarantine; ..."
# ??????????????????????
# ??? C: ?????? ?????????????????
_dmarc.sub.example.com. IN TXT "v=DMARC1; p=none; ..."
# ???????sub.example.com ??DMARC ???7.2 ???????????/h3>
d= ??header.from ???????????.com.cn??code>.co.uk????????DMARC ????????? example.co.uk ????????? DMARC ?????????????????/p>
# ??? publicsuffix.org ??API ????????curl -s https://publicsuffix.org/list/public_suffix_list.dat | \
grep -E '^// (cn|uk|jp)' | head -5
# ???????????PSL ?????python3 -c "
from publicsuffix2 import get_sld
print(get_sld('sub.example.co.uk'))
# ???: example.co.uk
"??????????????
8.1 ???????????/h3>
p=reject ??????????????????????????????
??? ??? ?????? ??? ?????/td> p=none; rua=mailto:...2-4 ??/td> ???????????? ?????/td> p=quarantine; pct=251-2 ??/td> ???????????/td> ?????/td> p=quarantine; pct=1001-2 ??/td> ????????? ?????/td> p=reject; pct=251-2 ??/td> ?????? reject ?????/td> p=reject; pct=100??? ?????? 8.2 ?????????
# ??p=reject ?????p=quarantine????????# ??? DNS ???
_dmarc.example.com. IN TXT "v=DMARC1; p=quarantine; sp=quarantine; rua=mailto:dmarc@example.com; pct=50"
# ????????????????????????????????????
# ?????????????? DMARC ???????????????
# ???????????
# ??????????????parsedmarc -c /etc/parsedmarc/config.ini \
--aggregate-json-lines | \
jq 'select(.disposition == "reject") | {source_ip, header_from, count}' | \
head -208.3 ?????????????????/h3>
# Gmail ????????????
# https://support.google.com/mail/contact/msgdelivery
# Microsoft SNDS (Smart Network Data Services)
# https://sendersupport.olc.protection.outlook.com/snds/
# Yahoo ????????# https://help.yahoo.com/kb/SLN3428.html???????/h3>
引用本文
