1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Route53にほどよい設定のDMARCレコードを登録をする

Posted at

1.以下を CloudShell に貼り付ける

cat <<'EOL' > set_dmarc.sh
#!/bin/bash

# 引数の確認
if [ "$#" -ne 2 ]; then
    echo "使用法: $0 [ドメイン名] [メールアドレス]"
    exit 1
fi

DOMAIN=$1
EMAIL=$2

# ホストゾーンIDの取得
HOSTED_ZONE_ID=$(aws route53 list-hosted-zones | jq -r --arg domain "$DOMAIN." '.HostedZones[] | select(.Name==$domain) | .Id')

# ホストゾーンIDが見つからない場合のエラー処理
if [ -z "$HOSTED_ZONE_ID" ]; then
    echo "ホストゾーンIDが見つかりません: $DOMAIN"
    exit 1
fi

# DMARCレコードの設定
DMARC_RECORD='"\"v=DMARC1; p=quarantine;sp=quarantine;pct=100;adkim=r; rua=mailto:'$EMAIL';\""'

aws route53 change-resource-record-sets --hosted-zone-id "$HOSTED_ZONE_ID" --change-batch "{
  \"Changes\": [{
    \"Action\": \"UPSERT\",
    \"ResourceRecordSet\": {
      \"Name\": \"_dmarc.$DOMAIN\",
      \"Type\": \"TXT\",
      \"TTL\": 300,
      \"ResourceRecords\": [{ \"Value\": $DMARC_RECORD }]
    }
  }]
}"
EOL

chmod +x set_dmarc.sh

2../set_dmarc.sh <ドメイン名> <emailアドレス> を実行

mailtoのドメインとホストゾーンのドメインが異なる場合

External Destination Verification を設定すること。

レコード名:<上記のホストゾーンのドメイン>._report._dmarc.<mailtoのドメイン>
値: "v=DMARC1"

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?