# メール構成コマンド

## 概要 <a href="#overview" id="overview"></a>

`email-config` コマンドは、コマンダーから直接ワンタイム共有リンクや通知を送信するために使用されるメールプロバイダの構成を管理します。構成はKeeperボルト内に暗号化されて保存されます。コマンダーを通じて安全なメールを送信することで、ゼロ知識が維持され、Keeperのバックエンドサーバーはコンテンツにアクセスできません。

**対応プロバイダ**

* **SMTP** - すべてのインストールで利用可能 (バイナリ、pip、\[email]付きpip)
* **SendGrid** - `pip install keepercommander[email]` でのみ利用可能
* **AWS SES** - `pip install keepercommander[email]` でのみ利用可能
* **Gmail OAuth** - `pip install keepercommander[email]` でのみ利用可能
* **Microsoft OAuth** - `pip install keepercommander[email]` でのみ利用可能

{% hint style="warning" %}
バイナリインストールおよび基本的なpipインストール `pip install keepercommander` はSMTPのみに対応しています。
{% endhint %}

## 活用事例

メール構成は、Keeperのサーバー経由でメールを送信する代わりに、顧客が構成したメールプロバイダを使用して、コマンダーから直接メールを送信する場合に使用されます。以下の事例が活用できます。

* `record-add` コマンドでワンタイム共有リンクを送信
* `pam action rotate` コマンドでパスワードをローテーションしワンタイム共有を送信
* `credential-provision` コマンドで新入社員の認証情報のローテーションと配布を自動化

## メール構成コマンド

| [`create`](#email-config-create) | 新しいメールプロバイダ構成を作成      |
| -------------------------------- | --------------------- |
| [`list`](#email-config-list)     | 構成済みのメールプロバイダをすべて一覧表示 |
| [`test`](#email-config-test)     | メール構成をテスト             |
| [`delete`](#email-config-delete) | メール構成を削除              |
| [`update`](#email-config-update) | 既存のメール構成を更新           |

### email-config create <a href="#email-config-create" id="email-config-create"></a>

**コマンド:** `email-config create`

**詳細:** 新しいメールプロバイダ構成を作成します。構成はKeeperボルト内に暗号化されて保存され、`record-add` および `one-time-share` コマンドと併用できます。

**共通パラメータ**

* `--name <NAME>` - 構成名 (必須)
* `--provider <PROVIDER>` - プロバイダ種別: `smtp`, `sendgrid`, `ses`, `gmail-oauth`, `microsoft-oauth` (必須)
* `--from-address <EMAIL>` - 送信元メールアドレス (必須)
* `--from-name <NAME>` - 送信者表示名 (任意)

**SMTPプロバイダのパラメータ**

* `--smtp-host <HOST>` - SMTPサーバーのホスト名
* `--smtp-port <PORT>` - SMTPサーバーのポート (デフォルト: 587)
* `--smtp-username <USERNAME>` - SMTPユーザー名
* `--smtp-password <PASSWORD>` - SMTPパスワード
* `--smtp-use-tls` | `--smtp-no-tls` - TLSを有効化・無効化
* `--smtp-use-ssl` - SSLを有効化

**SendGridプロバイダのパラメータ**

* `--sendgrid-api-key <KEY>` - SendGrid APIキー

**AWS SESプロバイダのパラメータ**

* `--aws-region <REGION>` - AWSリージョン (例: us-east-1)
* `--aws-access-key <KEY>` - AWSアクセスキーID
* `--aws-secret-key <SECRET>` - AWSシークレットアクセスキー

**OAuthプロバイダのパラメータ (GmailおよびMicrosoft)**

* `--oauth-client-id <ID>` - OAuthクライアントID
* `--oauth-client-secret <SECRET>` - OAuthクライアントシークレット
* `--oauth-tenant-id <ID>` - AzureテナントID (Microsoftのみ。マルチテナントの場合は「common」を使用)
* `--oauth-port <PORT>` - ローカルコールバックポート (デフォルト: 8080)

**OAuth手動トークンパラメータ (上級者向け)**

* `--oauth-access-token <TOKEN>` - アクセストークン
* `--oauth-refresh-token <TOKEN>` - リフレッシュトークン
* `--oauth-token-expiry <DATETIME>` - トークン有効期限 (ISO-8601形式)

**例**

```bash
# GmailのSMTP
email-config create \
  --name 'SMTP-Gmail' \
  --provider smtp \
  --from-address 'you@gmail.com' \
  --from-name 'Your Name' \
  --smtp-host 'smtp.gmail.com' \
  --smtp-port 587 \
  --smtp-use-tls \
  --smtp-use-ssl \
  --smtp-username 'you@gmail.com' \
  --smtp-password 'app-password'

# SendGrid
email-config create \
  --name 'SendGrid' \
  --provider sendgrid \
  --from-address 'verified@yourdomain.com' \
  --sendgrid-api-key 'SG.xxx'

# Gmail OAuth（対話型フロー）
email-config create \
  --name 'Gmail-OAuth' \
  --provider gmail-oauth \
  --from-address 'you@gmail.com' \
  --oauth-client-id 'YOUR_CLIENT_ID.apps.googleusercontent.com' \
  --oauth-client-secret 'YOUR_CLIENT_SECRET'

# Microsoft OAuth
email-config create \
  --name 'Microsoft-OAuth' \
  --provider microsoft-oauth \
  --from-address 'you@company.com' \
  --oauth-client-id 'YOUR_APPLICATION_ID' \
  --oauth-client-secret 'YOUR_CLIENT_SECRET' \
  --oauth-tenant-id 'YOUR_TENANT_ID'

# AWS SES
email-config create \
  --name 'AWS-SES' \
  --provider ses \
  --from-address 'verified@yourdomain.com' \
  --aws-region 'us-east-1' \
  --aws-access-key 'AKIA...' \
  --aws-secret-key 'xxx'
```

1. SMTPの例は、アプリパスワード認証を用いたGmailのSMTPサーバーを使用します。ポート587で「Use TLS」を「true」に設定するか、ポート465で「Use SSL」を「true」に設定してください。
2. SendGridは、検証済み送信ドメインとAPIキーが必要です
3. Gmail OAuthは認可のためにブラウザを開きます (トークンはボルトに保存)
4. Microsoft OAuthはシングルテナントおよびマルチテナント構成をサポートします
5. AWS SESは、SESの送信権限を持つIAM認証情報が必要です

{% hint style="info" %}
Googleアカウントの場合、<https://myaccount.google.com/apppasswords> ににアクセスし、メール配信用のアプリケーションパスワードを作成してください。
{% endhint %}

### email-config list

**コマンド**

`email-config list`

**詳細**

構成済みのメールプロバイダをすべて基本情報とともに表示します。

**例**

```bash
email-config list
```

**出力**

```
Email Configurations:
  Name                Provider          From Address
  ─────────────────────────────────────────────────────────
  Gmail-OAuth         gmail-oauth       you@gmail.com
  SMTP-Office365      smtp              admin@company.com
  SendGrid-Main       sendgrid          [email protected]
```

### email-config test

**コマンド**

`email-config test <NAME>`

**詳細**

接続と認証を検証してメール構成をテストします。任意でテストメールを送信できます。

**パラメータ**

* `<NAME>` - テストする構成名
* `--send-to <EMAIL>` - 指定したアドレスにテストメールを送信（任意）

**例**

```bash
# 接続のみをテスト（メールは送信されません）
email-config test 'Gmail-OAuth'

# 実際にテストメールを送信
email-config test 'Gmail-OAuth' --send-to 'recipient@example.com'
```

**出力 (接続テスト)**

```
Testing connection for "Gmail-OAuth" (gmail-oauth)...
[EMAIL] Gmail OAuth connection successful: you@gmail.com
✓ Connection test successful for "Gmail-OAuth"
```

**出力 (--send-to)**

```
Testing connection for "Gmail-OAuth" (gmail-oauth)...
[EMAIL] Sending test email to recipient@example.com...
[EMAIL] Test email sent successfully
✓ Connection test successful for "Gmail-OAuth"
```

### email-config delete

**コマンド**

`email-config delete <NAME>`

**詳細**

Keeperボルトからメール構成を削除します。

**パラメータ**

* `<NAME>` - 削除する構成名

**例**

```bash
email-config delete 'Old-SMTP-Config'
```

### email-config update

**コマンド**

`email-config update <NAME> [OPTIONS]`

**詳細**

既存のメール構成を更新します。次と同じパラメータを受け付けます `create` コマンド。

**パラメータ**

* `<NAME>` - 更新する構成名
* `[OPTIONS]` - 次と同じオプション: `create` コマンド

**例**

```bash
# SMTPパスワードを更新
email-config update 'SMTP-Gmail' --smtp-password 'new-app-password'

# 送信者名を更新
email-config update 'Gmail-OAuth' --from-name 'New Display Name'
```

***

## メール構成の使用 <a href="#using-email-configurations" id="using-email-configurations"></a>

メール構成は、メール配信をサポートするコマンドと一緒に使用します。

**record-add を使用する場合**

```bash
record-add --record-type login \
  --title 'Server Access' \
  login=admin \
  password=$GEN \
  --self-destruct 24h \
  --email-config 'Gmail-OAuth' \
  --send-email 'recipient@example.com'
```

## インストール要件

メールプロバイダのサポートはインストール方法に依存します。

| プロバイダ           | バイナリ | pip (基本) | pip \[email] |
| --------------- | ---- | -------- | ------------ |
| SMTP            | ✅    | ✅        | ✅            |
| SendGrid        | ❌    | ❌        | ✅            |
| AWS SES         | ❌    | ❌        | ✅            |
| Gmail OAuth     | ❌    | ❌        | ✅            |
| Microsoft OAuth | ❌    | ❌        | ✅            |

**完全なメールサポートでインストール**

```bash
pip install keepercommander[email]
```

## OAuth対話型フロー <a href="#oauth-interactive-flow" id="oauth-interactive-flow"></a>

`--oauth-access-token` なしでGmailまたはMicrosoftのOAuth構成を作成する場合 、対話型の認可フローを開始します。

1. ローカルウェブサーバーがポート8080で起動（`--oauth-port` で設定可能)
2. ブラウザがプロバイダの認可ページを開く
3. ユーザーがログインしてアプリケーションを承認
4. ブラウザが認可コード付きでlocalhostにリダイレクト
5. コマンダーがコードをトークンに交換
6. トークンは暗号化されKeeperボルトに保存

**トークン管理**

* アクセストークンは1時間で期限切れ
* コマンダーはリフレッシュトークンを使用して自動的に更新
* トークンが期限切れの場合、メール送信前に更新が実行される
* 更新されたトークンは自動的にボルトに保存

***

## トラブルシューティング <a href="#troubleshooting" id="troubleshooting"></a>

**エラー: 「Provider is not available in the binary installation」**

バイナリインストールはSMTPのみサポートします。pipインストールに切り替えてます。

```bash
pip install keepercommander[email]
```

**エラー: 「Missing required dependencies for provider」**

メール拡張付きでインストールします。

```bash
pip install --upgrade keepercommander[email]
```

**エラー: 「Interactive OAuth flow is not available on binary installation」**

オプション

1. pipインストールに切り替える (推奨)
2. 代わりにSMTPプロバイダを使用します。
3. `--oauth-access-token`, `--oauth-refresh-token`, `--oauth-token-expiry` を使用してOAuthトークンを手動で提供

**エラー: 「Port 8080 already in use」**

OAuthコールバックに別のポートを使用します。

```bash
email-config create ... --oauth-port 9090
```

**エラー: 「email-config not found」**

構成名が存在しません。利用可能な構成を一覧表示します。

```bash
email-config list
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keeper.io/keeperpam/jp/commander-cli/command-reference/email-configuration-commands.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
