次の方法で共有


Email Communication Service リソースの作成と管理

最初の Email Communication Service リソースをプロビジョニングして、Email の使用を開始します。 Azure portal または .NET 管理クライアント ライブラリを使用して、電子メール通信サービス リソースをプロビジョニングします。 管理クライアント ライブラリと Azure portal を使用すると、Azure のデプロイと管理サービスである Azure Resource Manager を使用して、リソースとインターフェイスを作成、構成、更新、削除できます。 クライアント ライブラリで使用できるすべての関数は、Azure portal で使用できます。

警告

Azure Communication Services のリソースと同時にリソース グループを作成することはできません。 最初にリソース グループを作成してから、電子メール リソースをプロビジョニングするときに使用する必要があります。

前提条件

ポータルを使用して Email Communications Service リソースを作成する

  1. Azure portal を開いて新しいリソースを作成します。

  2. 電子メール通信サービスを検索します。

    市場で電子メール通信サービスを検索する方法を示すスクリーンショット。

  3. [ Email Communication Services ] を選択し、[ 作成] をクリックします。

    電子メール通信サービスを作成するための [作成] リンクを示すスクリーンショット。

  4. [ 基本 ] タブに必要な情報を入力します。

    • 既存の Azure サブスクリプションを選択します。

    • 既存のリソース グループを選択するか、新しいリソース グループを作成するには、[ 新規作成 ] リンクをクリックします。

    • リソースの有効な名前を指定します。

    • リソースを使用できる必要があるリージョンを選択します。

    • データの場所として [米国] を選択します。

    • タグを追加するには、[次へ: タグ] をクリックします。

    • 任意の名前と値のペアを追加します。

      確認と電子メール通信サービスの作成の概要を示すスクリーンショット。

  5. [次へ: 確認と作成] をクリックします。

  6. 検証が完了するまで待ってから、[ 作成] をクリックします。

  7. デプロイが完了するまで待ってから、[ リソースに移動 ] をクリックして、電子メール通信サービスの概要を開きます。

    Email Communication Service リソースの概要を示すスクリーンショット。

前提条件

Email Communication Services リソースを作成する

Email Communication Services リソースを作成するには、 Azure CLI にサインインします。 ターミナルから az login コマンドを実行し、資格情報を入力してサインインできます。 リソースを作成するには、次のコマンドを実行します:

az communication email create --name "<EmailServiceName>" --___location "Global" --data-___location "United States" --resource-group "<resourceGroup>"

特定のサブスクリプションを選択する場合は、 --subscription フラグを指定し、サブスクリプション ID を指定することもできます。

az communication email create --name "<EmailServiceName>" --___location "Global" --data-___location "United States" --resource-group "<resourceGroup>" --subscription "<subscriptionId>"

次のオプションを使用して、Email Communication Services リソースを構成できます。

次の手順では、リソースにタグを割り当てることができます。 その後、タグを使用して Azure Email リソースを整理できます。 タグの詳細については、リソースのタグ付けに関するドキュメントを参照してください。

メールコミュニケーションサービスのリソースを管理する

Email Communication Services リソースにタグを追加するには、次のコマンドを実行します。 また、特定のサブスクリプションを対象にすることもできます。

az communication email update --name "<EmailServiceName>" --tags newTag="newVal1" --resource-group "<resourceGroup>"

az communication email update --name "<EmailServiceName>" --tags newTag="newVal2" --resource-group "<resourceGroup>" --subscription "<subscriptionId>"

特定のリソース グループ内のすべての電子メール通信サービス リソースを一覧表示するには、次のコマンドを使用します。

az communication email list --resource-group "<resourceGroup>"

特定の Email Communication Service リソースのすべての情報を表示するには、次のコマンドを使用します。 また、特定のサブスクリプションを対象にすることもできます。

az communication email show --name "<EmailServiceName>" --resource-group "<resourceGroup>"

az communication email show --name "<EmailServiceName>" --resource-group "<resourceGroup>" --subscription "<subscriptionId>"

リソースのクリーンアップ

Email Communication Services サブスクリプションをクリーンアップして削除する場合は、リソースまたはリソース グループを削除できます。 次のコマンドを実行して、電子メール通信リソースを削除できます。

az communication email delete --name "<EmailServiceName>" --resource-group "<resourceGroup>"

リソース グループを削除すると、それに関連付けられている他のリソースも削除されます。

リソースの削除は永続的であり、リソースを削除すると、Event Grid フィルター、電話番号など、リソースに関連付けられたデータを含むデータを復元できなくなります。

その他のコマンドについては、 電子メール通信 CLI を参照してください。

前提条件

SDK をインストールする

まず、Communication Services Management SDK を C# プロジェクトにインクルードします。

using Azure.ResourceManager.Communication;

サブスクリプション ID

Azure サブスクリプションの ID を把握しておく必要があります。 この ID は、ポータルから取得できます。

  1. Azure アカウントにサインインします。
  2. 左側のサイドバーで [サブスクリプション] を選択します。
  3. 必要なサブスクリプションを選択します。
  4. [概要] をクリックします。
  5. サブスクリプションIDを選択します。

このクイック スタートでは、サブスクリプション ID を AZURE_SUBSCRIPTION_ID という環境変数に格納していることを前提としています。

認証

Azure Communication Services と通信するには、まず Azure に対して自分自身を認証する必要があります。

クライアントを認証する

認証されたクライアントを作成する既定のオプションは、DefaultAzureCredentialを使用することです。 すべての管理 API は同じエンドポイントを経由するため、リソースを操作するには、最上位レベルの ArmClientを 1 つだけ作成する必要があります。

Azure に対して認証し、 ArmClientを作成するには、次のコードを実行します。

using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Communication;
using Azure.ResourceManager.Resources;
...
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);

Azure リソースとの操作

これで認証されました。

次の各例では、Email Services リソースを既存のリソース グループに割り当てます。

リソース グループを作成する必要がある場合は、Azure portal または Azure Resource Manager SDK を使用して実行できます。

電子メール サービス リソースを作成する

Email Services リソースを作成するときは、リソース グループ名とリソース名を指定します。

Location プロパティは常に global であり、パブリック プレビュー中は、DataLocation 値を UnitedStates にする必要があります。

// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e";
string resourceGroupName = "MyResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);

// get the collection of this EmailServiceResource
EmailServiceResourceCollection collection = resourceGroupResource.GetEmailServiceResources();

// invoke the operation
string emailServiceName = "MyEmailServiceResource";
EmailServiceResourceData data = new EmailServiceResourceData(new AzureLocation("Global"))
{
    DataLocation = "United States",
};
ArmOperation<EmailServiceResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, emailServiceName, data);
EmailServiceResource result = lro.Value;

// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
EmailServiceResourceData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");

メールコミュニケーションサービスのリソースを管理する

電子メール通信サービスのリソースを更新する

...
// this example assumes you already have this EmailServiceResource created on azure
// for more information of creating EmailServiceResource, please refer to the document of EmailServiceResource
string subscriptionId = "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e";
string resourceGroupName = "MyResourceGroup";
string emailServiceName = "MyEmailServiceResource";
ResourceIdentifier emailServiceResourceId = EmailServiceResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, emailServiceName);
EmailServiceResource emailServiceResource = client.GetEmailServiceResource(emailServiceResourceId);

// invoke the operation
EmailServiceResourcePatch patch = new EmailServiceResourcePatch()
{
    Tags =
    {
    ["newTag"] = "newVal",
    },
};
ArmOperation<EmailServiceResource> lro = await emailServiceResource.UpdateAsync(WaitUntil.Completed, patch);
EmailServiceResource result = lro.Value;

// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
EmailServiceResourceData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");

すべての電子メール通信サービス リソースをリソース グループ別に一覧表示する

// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e";
string resourceGroupName = "MyResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);

// get the collection of this EmailServiceResource
EmailServiceResourceCollection collection = resourceGroupResource.GetEmailServiceResources();

// invoke the operation and iterate over the result
await foreach (EmailServiceResource item in collection.GetAllAsync())
{
    // the variable item is a resource, you could call other operations on this instance as well
    // but just for demo, we get its data from this resource instance
    EmailServiceResourceData resourceData = item.Data;
    // for demo we just print out the id
    Console.WriteLine($"Succeeded on id: {resourceData.Id}");
}

Console.WriteLine($"Succeeded");

サブスクリプションごとにすべての電子メール通信サービス リソースを一覧表示する

// this example assumes you already have this SubscriptionResource created on azure
// for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource
string subscriptionId = "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e";
ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId);
SubscriptionResource subscriptionResource = client.GetSubscriptionResource(subscriptionResourceId);

// invoke the operation and iterate over the result
await foreach (EmailServiceResource item in subscriptionResource.GetEmailServiceResourcesAsync())
{
    // the variable item is a resource, you could call other operations on this instance as well
    // but just for demo, we get its data from this resource instance
    EmailServiceResourceData resourceData = item.Data;
    // for demo we just print out the id
    Console.WriteLine($"Succeeded on id: {resourceData.Id}");
}

Console.WriteLine($"Succeeded");

リソースのクリーンアップ

// this example assumes you already have this EmailServiceResource created on azure
// for more information of creating EmailServiceResource, please refer to the document of EmailServiceResource
string subscriptionId = "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e";
string resourceGroupName = "MyResourceGroup";
string emailServiceName = "MyEmailServiceResource";
ResourceIdentifier emailServiceResourceId = EmailServiceResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, emailServiceName);
EmailServiceResource emailServiceResource = client.GetEmailServiceResource(emailServiceResourceId);

// invoke the operation
await emailServiceResource.DeleteAsync(WaitUntil.Completed);

Console.WriteLine($"Succeeded");

リソースの削除は永続的であり、リソースを削除すると、Event Grid フィルター、電話番号など、リソースに関連付けられたデータを含むデータを復元できなくなります。

前提条件

電子メール通信サービス リソースを作成する

Email Communication Service リソースを作成するには、次のコマンドを使用して Connect-AzAccount を使用して Azure アカウントにサインインし、資格情報を入力します。

PS C:\> Connect-AzAccount

まず、次のコマンドを実行して、Azure Communication Services モジュール Az.Communication をインストールします。

PS C:\> Install-Module Az.Communication

リソースを作成するには、次のコマンドを実行します。

PS C:\> New-AzEmailService -ResourceGroupName ContosoResourceProvider1 -Name ContosoEmailServiceResource1 -DataLocation UnitedStates

特定のサブスクリプションを選択する場合は、 --subscription フラグを指定し、サブスクリプション ID を指定することもできます。

PS C:\> New-AzEmailService -ResourceGroupName ContosoResourceProvider1 -Name ContosoEmailServiceResource1 -DataLocation UnitedStates -SubscriptionId SubscriptionID

以下のオプションを使用して、Communication Services のリソースを構成できます。

次の手順では、リソースにタグを割り当てることができます。 タグを使用して Azure Email リソースを整理します。 タグの詳細については、 リソースのタグ付けを参照してください。

メールコミュニケーションサービスのリソースを管理する

Email Communication Services リソースにタグを追加するには、次のコマンドを実行します。 また、特定のサブスクリプションを対象にすることもできます。

PS C:\> Update-AzEmailService -Name ContosoEmailServiceResource1 -ResourceGroupName ContosoResourceProvider1 -Tag @{ExampleKey1="ExampleValue1"}

PS C:\> Update-AzEmailService -Name ContosoEmailServiceResource1 -ResourceGroupName ContosoResourceProvider1 -Tag @{ExampleKey1="ExampleValue1"} -SubscriptionId SubscriptionID

特定のサブスクリプション内のすべての Email Communication Service リソースを一覧表示するには、次のコマンドを使用します。

PS C:\> Get-AzEmailService -SubscriptionId SubscriptionID

特定のリソースのすべての情報を一覧表示するには、次のコマンドを使用します。

PS C:\> Get-AzEmailService -Name ContosoEmailServiceResource1 -ResourceGroupName ContosoResourceProvider1

リソースのクリーンアップ

Email Communication Services リソースをクリーンアップして削除する場合は、次のコマンドを実行して、電子メール通信リソースを削除できます。

PS C:\> Remove-AzEmailService -Name ContosoEmailServiceResource1 -ResourceGroupName ContosoResourceProvider1

リソースの削除は永続的であり、リソースを削除すると、Event Grid フィルター、電話番号など、リソースに関連付けられたデータを含むデータを復元できなくなります。

次のステップ