

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# SES での E メール添付ファイルの操作
<a name="attachments"></a>

SES の E メール添付ファイルは、SES API v2 の `SendEmail` および `SendBulkEmail` オペレーションを使用するときに E メールメッセージに含めることができるファイルです。この機能を使用すると、SES でサポートされている MIME タイプに準拠する PDF、Word ファイル、イメージ、またはその他のファイルタイプのドキュメントを含めることで、E メールコンテンツを充実させることができます。また、受信者が個別にダウンロードすることなく、E メールコンテンツに直接レンダリングされるインラインイメージを含めることもできます。1 通の E メールに複数の添付ファイルを含めることができます。メッセージの合計サイズの上限は 40 MB です。

**注記**  
`Raw` コンテンツタイプ、SMTP インターフェイス、および SES API v1 を使用する [https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendEmail.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendEmail.html) SES API v2 は、[raw E メール MIME メッセージ構造](send-email-raw.md#send-email-raw-mime)を通じて添付ファイルを引き続き処理します。

## SES での添付ファイルの仕組み
<a name="how-attachments-work"></a>

添付ファイルを含む E メールを送信する場合、各段階で発生するエンコードには 2 つの異なるタイプがあります。

ステージ 1 – SES へのデータの送信:
+ 添付ファイルを SES に送信する場合は、バイナリデータ (PDF や画像など) を安全に送信できる形式に変換する必要があります。
+ ここで base64 エンコードがその役割を果たします。base64 エンコードが必要となるのは、JSON リクエストで raw バイナリデータを送信できないためです。
+  AWS SDK を使用している場合、このエンコーディングは自動的に処理されます。
+ を使用している場合は AWS CLI、送信する前にアタッチメントを base64 でエンコードする必要があります。

ステージ 2 – SES による E メールの作成:
+ SES は、データを受信したら、添付ファイルを含む実際の E メールを作成する必要があります。
+ ここで、[ContentTransferEncoding](#attachment-structure) 設定がその役割を果たします。
+ SES は ContentTransferEncoding で指定したエンコード方法を使用して、最終的な E メールの添付ファイルを自動的にフォーマットします。

これは、郵送で荷物を送る作業に似ています。まず、荷物を郵便局に持ち込む必要があります (ステージ 1 – Base64 エンコードが必要)。その後、郵便局は最終的な配送のため、荷物を適切に梱包します (ステージ 2 – ContentTransferEncoding)。

## 添付ファイルオブジェクトの構造
<a name="attachment-structure"></a>

SES 経由で添付ファイルを含む E メールを送信すると、サービスは複雑な MIME メッセージ構造を自動的に処理します。次の SES API v2 [https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_Attachment.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_Attachment.html) オブジェクト構造に従って、添付ファイルの内容とメタデータを提供するだけで済みます。
+ `FileName` (必須) – 受信者に表示されるファイル名 (ファイル拡張子を含める必要があります)。指定しない場合、SES は `FileName` の拡張機能から `ContentType` を取得します。
+ `ContentType` (オプション) – [IANA 準拠のメディアタイプ識別子](https://www.iana.org/assignments/media-types/media-types.xhtml)。
+ `ContentDisposition` (オプション) – 添付ファイルのレンダリング方法を指定します: `ATTACHMENT` *(デフォルト)* または `INLINE`。
+ `ContentDescription` (オプション) – コンテンツの簡単な説明。
+ `RawContent` (必須) – 添付ファイルの実際のコンテンツ。
+ `ContentTransferEncoding` (オプション) – 添付ファイルのペイロードを E メールの mime メッセージにアセンブルするときにエンコードする方法を指定します: `SEVEN_BIT` *(デフォルト)*、`BASE64` または `QUOTED_PRINTABLE`。

アタッチされたすべてのコンテンツは、送信のために SES エンドポイントに転送する前に base64 にエンコードする必要があります。 AWS SDK クライアントを使用して API コールを行う場合は、自動的に処理されます。を使用している場合 AWS CLI、または独自のクライアントを実装している場合は、次のようなエンコードを自分で実行する必要があります。
+ プレーンテキストの内容: `Text attachment sample content.`
+ Base64 エンコード: `VGV4dCBhdHRhY2htZW50IHNhbXBsZSBjb250ZW50Lg==`

次の例は、SES API v2 でアタッチメントを指定するときにアタッチメントオブジェクト構造を使用する方法[https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendEmail.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendEmail.html)と、アタッチメントオブジェクト要素を含む JSON ファイル AWS CLI を参照する[https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendBulkEmail.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendBulkEmail.html)オペレーションを示しています。

**Example – シンプルなコンテンツを含む SendEmail**  

```
aws sesv2 send-email --cli-input-json file://request-send-email-simple.json
```
**request-send-email-simple.json**  

```
{
    "FromEmailAddress": "sender@example.com",
    "Destination": {
        "ToAddresses": [
            "recipient@example.com"
        ]
    },
    "Content": {
        "Simple": {
            "Subject": {
                "Data": "Email with attachment"
            },
            "Body": {
                "Text": {
                    "Data": "Please see attached document."
                },
                "Html": {
                    "Data": "Please see attached <b>document</b>."
                }
            },
            "Attachments": [
                {
                    "RawContent": "<base64-encoded-content>",
                    "ContentDisposition": "ATTACHMENT",
                    "FileName": "document.pdf",
                    "ContentDescription": "PDF Document Attachment",
                    "ContentTransferEncoding": "BASE64"
                }
            ]
        }
    }
}
```

**Example – シンプルなコンテンツとインライン添付ファイルを含む SendEmail**  

```
aws sesv2 send-email --cli-input-json file://request-send-email-simple-inline-attachment.json
```
**request-send-email-simple-inline-attachment.json**  

```
{
    "FromEmailAddress": "sender@example.com",
    "Destination": {
        "ToAddresses": [
            "recipient@example.com"
        ]
    },
    "Content": {
        "Simple": {
            "Subject": {
                "Data": "Email with attachment"
            },
            "Body": {
                "Html": {
                    "Data": "<html><body>Our logo:<br><img src=\"cid:logo123\" alt=\"Company Logo\"></body></html>"
                }
            },
            "Attachments": [
                {
                    "RawContent": "<base64-encoded-content>",
                    "ContentDisposition": "INLINE",
                    "FileName": "logo.png",
                    "ContentId": "logo123",
                    "ContentTransferEncoding": "BASE64"
                }
            ]
        }
    }
}
```

**Example – テンプレートコンテンツを含む SendEmail**  

```
aws sesv2 send-email --cli-input-json file://request-send-email-template.json
```
**request-send-email-template.json**  

```
{
    "FromEmailAddress": "sender@example.com",
    "Destination": {
        "ToAddresses": [
            "recipient@example.com"
        ]
    },
    "Content": {
        "Template": {
            "TemplateName": "MyTemplate",
            "TemplateData": "{\"name\":\"John\"}",
            "Attachments": [
                {
                    "RawContent": "<base64-encoded-content>",
                    "ContentDisposition": "ATTACHMENT",
                    "FileName": "document.pdf",
                    "ContentDescription": "PDF Document Attachment",
                    "ContentTransferEncoding": "BASE64"
                }
            ]
        }
    }
}
```

**Example – 添付ファイルコンテンツを含む SendBulkEmail**  

```
aws sesv2 send-bulk-email --cli-input-json file://request-send-bulk-email.json
```
**request-send-bulk-email.json**  

```
{
    "FromEmailAddress": "sender@example.com",
    "DefaultContent": {
        "Template": {
            "TemplateName": "MyTemplate",
            "TemplateData": "{}",
            "Attachments": [
                {
                    "RawContent": "<base64-encoded-content>",
                    "ContentDisposition": "ATTACHMENT",
                    "FileName": "document.pdf",
                    "ContentDescription": "PDF Document Attachment",
                    "ContentTransferEncoding": "BASE64"
                }
            ]
        }
    },
    "BulkEmailEntries": [
        {
            "Destination": {
                "ToAddresses": [
                    "recipient@example.com"
                ]
            },
            "ReplacementEmailContent": {
                "ReplacementTemplate": {
                    "ReplacementTemplateData": "{\"name\":\"John\"}"
                }
            }
        }
    ]
}
```

## ベストプラクティス
<a name="attachments-best-practices"></a>
+ メッセージの合計サイズ (添付ファイルを含む) を 40 MB 未満に保ちます。
+ 可能であれば、SES がファイル拡張子に基づいてコンテンツタイプを自動検出できるようにします。
+ コンテンツタイプは、[一般的な MIME タイプ](https://developer.mozilla.org/en-US/docs/Web/HTTP/MIME_types/Common_types)から外れる場合にのみ明示的に指定します。
+ E メールのレンダリングを強化するため、インラインイメージの使用を検討します。
+ SES は、「[サポート対象外の添付ファイルのタイプ](#mime-types)」に記載されているものを除き、添付ファイルに対して幅広い MIME タイプをサポートしています。

## SES でサポート対象外の添付ファイルのタイプ
<a name="mime-types"></a>

多目的インターネットメール拡張‎ (MIME) スタンダードを使用して、Amazon SES 経由で送信メッセージにファイルを添付できます。Amazon SES は、すべての添付ファイルのタイプを受け入れます。しかし次のリストのファイル拡張子を持つ添付ファイルは*例外*です。


|  |  |  |  |  | 
| --- |--- |--- |--- |--- |
| .ade<br />.adp<br />.app<br />.asp<br />.bas<br />.bat<br />.cer<br />.chm<br />.cmd<br />.com<br />.cpl<br />.crt<br />.csh<br />.der<br />.exe<br />.fxp<br />.gadget<br />.hlp | .hta<br />.inf<br />.ins<br />.isp<br />.its<br />.js<br />.jse<br />.ksh<br />.lib<br />.lnk<br />.mad<br />.maf<br />.mag<br />.mam<br />.maq<br />.mar<br />.mas<br />.mat | .mau<br />.mav<br />.maw<br />.mda<br />.mdb<br />.mde<br />.mdt<br />.mdw<br />.mdz<br />.msc<br />.msh<br />.msh1<br />.msh2<br />.mshxml<br />.msh1xml<br />.msh2xml<br />.msi<br />.msp | .mst<br />.ops<br />.pcd<br />.pif<br />.plg<br />.prf<br />.prg<br />.reg<br />.scf<br />.scr<br />.sct<br />.shb<br />.shs<br />.sys<br />.ps1<br />.ps1xml<br />.ps2<br />.ps2xml | .psc1<br />.psc2<br />.tmp<br />.url<br />.vb<br />.vbe<br />.vbs<br />.vps<br />.vsmacros<br />.vss<br />.vst<br />.vsw<br />.vxd<br />.ws<br />.wsc<br />.wsf<br />.wsh<br />.xnk | 

ISP によっては他にも制限があります (添付ファイルのアーカイブに関する制限など)。実際に本稼働する前に大手 ISP を使って E メール送信をテストするようお勧めします。