

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 傳送政策範例
<a name="sending-authorization-policy-examples"></a>

傳送授權可讓您指定精確的條件，需符合這些條件才可允許委託寄件者代表您傳送。

**Topics**
+ [發送授權的特定條件](#sending-authorization-policy-conditions)
+ [指定委託寄件者](#sending-authorization-policy-example-sender)
+ [限制「寄件人」地址](#sending-authorization-policy-example-from)
+ [限制受委託者可傳送電子郵件的時間](#sending-authorization-policy-example-time)
+ [限制電子郵件傳送動作](#sending-authorization-policy-example-action)
+ [限制電子郵件寄件者的顯示名稱](#sending-authorization-policy-example-display-name)
+ [使用多個陳述式](#sending-authorization-policy-example-multiple-statements)

## 發送授權的特定條件
<a name="sending-authorization-policy-conditions"></a>

*條件*是關於陳述式內許可的任何限制。指定條件的陳述式部分可能是所有部分中最詳細的。*金鑰*是做為存取限制基準的特定特性，例如請求的日期和時間。

您同時使用條件和金鑰來表達限制。例如，若您希望限制委派寄件者代表您在 2019 年 7 月 30 日後向 Amazon SES 發出請求，您可以使用稱為 `DateLessThan` 的條件。您可以使用稱為 `aws:CurrentTime`的金鑰並將其設定為 `2019-07-30T00:00:00Z` 的值。

您可以使用 *IAM 使用者指南*中[可用](https://docs.aws.amazon.com/IAM/latest/UserGuide/AccessPolicyLanguage_ElementDescriptions.html#AvailableKeys)金鑰中列出的任何 AWS通用金鑰，也可以使用下列其中一個適用於 SES 的金鑰，這些金鑰有助於傳送授權政策：


****  

|  條件金鑰  |  Description  | 
| --- | --- | 
|   `ses:Recipients`   |  限制收件人地址，包括：「收件人」、「副本」和「密件副本」地址。  | 
|   `ses:FromAddress`   |  限制「寄件人」地址。  | 
|   `ses:FromDisplayName`   |  限制用於「寄件人」顯示名稱的字串內容 (有時稱為「方便從」)。例如，"John Doe <johndoe@example.com>" 的顯示名稱為 John Doe。  | 
|   `ses:FeedbackAddress`   |  限制「傳回路徑」地址，此地址可使用電子郵件意見回饋轉送功能來接收退信和投訴。如需關於電子郵件意見轉送功能的詳細資訊，請參閱 [透過電子郵件接收 Amazon SES 通知](monitor-sending-activity-using-notifications-email.md)。  | 

您可以搭配 Amazon SES 金鑰使用 `StringEquals` 和 `StringLike` 條件。這些條件用於區分大小寫字串的比對。針對 `StringLike`，其值可以在字串中的任何位置包含多字元比對萬用字元 (\$1) 或單一字元比對萬用字元 (?)。例如，以下條件會指定委派寄件者只能從以 *invoicing* 為開頭、以 *@example.com* 為結尾的 "From" 地址傳送：

```
1. "Condition": {
2.     "StringLike": {
3.       "ses:FromAddress": "invoicing*@example.com"
4.     }
5. }
```

您也可以使用 `StringNotLike` 條件，防止委託寄件者從特定電子郵件地址傳送電子郵件。例如，您可以在政策陳述式中包含以下條件，禁止從 *admin@example.com* 以及類似地址進行傳送，例如 *"admin"@example.com*、*admin\$11@example.com* 或 *sender@admin.example.com*：

```
1. "Condition": {
2.     "StringNotLike": {
3.       "ses:FromAddress": "*admin*example.com"
4.     }
5.  }
```

如需指定條件的詳細資訊，請參閱 *IAM 使用者指南*中的 [IAM JSON 政策元素：條件](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html)。

## 指定委託寄件者
<a name="sending-authorization-policy-example-sender"></a>

*委託人*是您授予許可的實體，可以是 AWS 帳戶、 AWS Identity and Access Management (IAM) 使用者或 AWS 服務。

下列範例顯示一個簡單的政策，允許 AWS ID *123456789012* 從已驗證的身分 *example.com* （由 AWS 帳戶 *888888888888* 擁有） 傳送電子郵件。此政策中的`Condition`陳述式僅允許委派人 （即 AWS ID *123456789012*) 從地址 *marketing\$1.\$1@example.com* 傳送電子郵件，其中 *\$1* 是寄件者在 *marketing\$1 之後想要新增的任何字串*。

------
#### [ JSON ]

****  

```
{
  "Id":"SampleAuthorizationPolicy",
  "Version":"2012-10-17",		 	 	 
  "Statement":[
    {
      "Sid":"AuthorizeMarketer",
      "Effect":"Allow",
      "Resource":"arn:aws:ses:us-east-1:888888888888:identity/example.com",
      "Principal":{
        "AWS":[
          "123456789012"
        ]
      },
      "Action":[
        "ses:SendEmail",
        "ses:SendRawEmail"
      ],
      "Condition":{
        "StringLike":{
          "ses:FromAddress":"marketing+.*@example.com"
        }
      }
    }
  ]
}
```

------

以下範例政策授予兩個 IAM 使用者從身分 *example.com* 傳送的許可。IAM 使用者由他們的 Amazon Resource Name (ARN) 指定。

------
#### [ JSON ]

****  

```
{
  "Id":"ExampleAuthorizationPolicy",
  "Version":"2012-10-17",		 	 	 
  "Statement":[
    {
      "Sid":"AuthorizeIAMUser",
      "Effect":"Allow",
      "Resource":"arn:aws:ses:us-east-1:888888888888:identity/example.com",
      "Principal":{
        "AWS":[
          "arn:aws:iam::111122223333:user/John",
          "arn:aws:iam::444455556666:user/Jane"
        ]
      },
      "Action":[
        "ses:SendEmail",
        "ses:SendRawEmail"
      ]
    }
  ]
}
```

------

以下範例政策將許可授予 Amazon Cognito，允許其從身分 *example.com* 傳送。

------
#### [ JSON ]

****  

```
{
  "Id":"ExampleAuthorizationPolicy",
  "Version":"2012-10-17",		 	 	 
  "Statement":[
    {
      "Sid":"AuthorizeService",
      "Effect":"Allow",
      "Resource":"arn:aws:ses:us-east-1:888888888888:identity/example.com",
      "Principal":{
        "Service":[
          "cognito-idp.amazonaws.com"
        ]
      },
      "Action":[
        "ses:SendEmail",
        "ses:SendRawEmail"
      ],
      "Condition": {
        "StringEquals": {
          "aws:SourceAccount": "888888888888",
          "aws:SourceArn": "arn:aws:cognito-idp:us-east-1:888888888888:userpool/your-user-pool-id-goes-here"
        }
      }
    }
  ]
}
```

------

以下範例政策將許可授予 AWS Organizations 中的所有帳戶，允許其從身分 example.com 傳送。 AWS Organization 是使用 [PrincipalOrgID](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principalorgid) 全域條件金鑰來指定。

------
#### [ JSON ]

****  

```
{
  "Id":"ExampleAuthorizationPolicy",
  "Version":"2012-10-17",		 	 	 
  "Statement":[
    {
      "Sid":"AuthorizeOrg",
      "Effect":"Allow",
      "Resource":"arn:aws:ses:us-east-1:888888888888:identity/example.com",
      "Principal":"*",
      "Action":[
        "ses:SendEmail",
        "ses:SendRawEmail"
      ],
      "Condition":{
        "StringEquals":{
          "aws:PrincipalOrgID":"o-xxxxxxxxxxx"
        }
      }
    }
  ]
}
```

------

## 限制「寄件人」地址
<a name="sending-authorization-policy-example-from"></a>

如果您使用驗證網域，可以會想要建立一個政策，只允許委託寄件者從指定的電子郵件地址中傳送。若要限制「寄件人」的地址，您需要在鍵上設定一個稱為 *ses:FromAddress* 的條件。下列政策可讓 AWS 帳戶 ID *123456789012* 從身分 *example.com* 傳送，但只能從電子郵件地址 *sender@example.com* 傳送。

------
#### [ JSON ]

****  

```
{
  "Id":"ExamplePolicy",
  "Version":"2012-10-17",		 	 	 
  "Statement":[
    {
      "Sid":"AuthorizeFromAddress",
      "Effect":"Allow",
      "Resource":"arn:aws:ses:us-east-1:888888888888:identity/example.com",
      "Principal":{
        "AWS":[
          "123456789012"
        ]
      },
      "Action":[
        "ses:SendEmail",
        "ses:SendRawEmail"
      ],
      "Condition":{
        "StringEquals":{
          "ses:FromAddress":"sender@example.com"
        }
      }
    }
  ]
}
```

------

## 限制受委託者可傳送電子郵件的時間
<a name="sending-authorization-policy-example-time"></a>

您也可以設定您的寄件者授權政策，因讓委託寄件者僅可於一天中的特定時間或者在特定日期範圍內傳送電子郵件。例如，如果您計劃在 2021 年 9 月傳送電子郵件行銷活動，您可以使用以下政策來限制受委託人僅能在該月份內傳送電子郵件。

------
#### [ JSON ]

****  

```
{
  "Id":"ExamplePolicy",
  "Version":"2012-10-17",		 	 	 
  "Statement":[
    {
      "Sid":"ControlTimePeriod",
      "Effect":"Allow",
      "Resource":"arn:aws:ses:us-east-1:888888888888:identity/example.com",
      "Principal":{
        "AWS":[
          "123456789012"
        ]
      },
      "Action":[
        "ses:SendEmail",
        "ses:SendRawEmail"
      ],
      "Condition":{
        "DateGreaterThan":{
          "aws:CurrentTime":"2021-08-31T12:00Z"
        },
        "DateLessThan":{
          "aws:CurrentTime":"2021-10-01T12:00Z"
        }
      }
    }
  ]
}
```

------

## 限制電子郵件傳送動作
<a name="sending-authorization-policy-example-action"></a>

寄件者可使用兩種動作來透過 Amazon SES 傳送電子郵件：`SendEmail` 和 `SendRawEmail`，取決於寄件者想要對電子郵件格式擁有多少控制權。傳送授權政策可讓您限制委託寄件者為以下兩種動作之一。但是，許多身分擁有者會在政策中啟用兩種動作，以讓委派寄件者決定電子郵件傳送呼叫的詳細資訊。

**注意**  
如果您想要讓委派寄件者透過 SMTP 界面存取 Amazon SES，您必須至少選擇 `SendRawEmail`。

如果您的使用案例是想要限制動作，可以只在傳送授權政策中加入一個動作。以下範例說明如何對 `SendRawEmail` 限制動作。

------
#### [ JSON ]

****  

```
{
  "Id":"ExamplePolicy",
  "Version":"2012-10-17",		 	 	 
  "Statement":[
    {
      "Sid":"ControlAction",
      "Effect":"Allow",
      "Resource":"arn:aws:ses:us-east-1:888888888888:identity/example.com",
      "Principal":{
        "AWS":[
          "123456789012"
        ]
      },
      "Action":[
        "ses:SendRawEmail"
      ]
    }
  ]
}
```

------

## 限制電子郵件寄件者的顯示名稱
<a name="sending-authorization-policy-example-display-name"></a>

部分電子郵件用戶端顯示電子郵件寄件者的「方便」名稱 (若電子郵件標題提供)，而非實際的「寄件人」地址。例如，"John Doe <johndoe@example.com>" 的顯示名稱為 John Doe。例如，您可能會從 *user@example.com* 傳送電子郵件，但是您想讓收件人看到該電子郵件是來自 *Marketing* (行銷)，而非來自 *user@example.com*。下列政策可讓 AWS 帳戶 ID 123456789012 從身分 *example.com* 傳送，但前提是「寄件人」地址的顯示名稱包含*行銷*。

------
#### [ JSON ]

****  

```
{
  "Id":"ExamplePolicy",
  "Version":"2012-10-17",		 	 	 
  "Statement":[
    {
      "Sid":"AuthorizeFromAddress",
      "Effect":"Allow",
      "Resource":"arn:aws:ses:us-east-1:888888888888:identity/example.com",
      "Principal":{
        "AWS":[
          "123456789012"
        ]
      },
      "Action":[
        "ses:SendEmail",
        "ses:SendRawEmail"
      ],
      "Condition":{
        "StringLike":{
          "ses:FromDisplayName":"Marketing"
        }
      }
    }
  ]
}
```

------

## 使用多個陳述式
<a name="sending-authorization-policy-example-multiple-statements"></a>

您的傳送授權政策可以包含多個陳述式。以下範例政策有兩個陳述式。第一個陳述式授權兩個從 *sender@example.com* AWS 帳戶 傳送，只要「寄件人」地址和意見回饋地址都使用網域 *example.com*。第二個陳述式授權 IAM 使用者從 *sender@example.com* 傳送，只要在收件人的電子郵件地址位於 *example.com* 網域內就能傳送。