クイック スタート: メール通信サービスのリソースを作成して管理する

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

警告

Azure Communication Services のリソースと同時にリソース グループを作成できないことに注意してください。 リソースを作成するときは、既に作成されているリソース グループを使用する必要があります。

前提条件

portal を使用してメール通信サービスのリソースを作成する

  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 リソースを構成できます:

  • リソース グループ
  • Email Communication Services リソースの名前
  • リソースが関連付けられる地理的な場所

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

Email Communication Services のリソースを管理する

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>"

特定のリソース グループ内のすべての Email Communication Services リソースを一覧表示するには、次のコマンドを使用します:

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

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

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>"

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

Note

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

その他のコマンドについては、Email Communication CLI を参照してください。

前提条件

SDK のインストール

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

using Azure.ResourceManager.Communication;

サブスクリプション ID

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

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

このクイックスタートでは、 AZURE_SUBSCRIPTION_ID という名前の環境変数にサブスクリプション 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://video2.skills-academy.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 リソースを作成する

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

Note

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 = "11112222-3333-4444-5555-666677778888";
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}");

Email Communication Services のリソースを管理する

Email Communication Services リソースを更新する

...
// 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 = "11112222-3333-4444-5555-666677778888";
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}");

すべての Email Communication Services リソースをリソース グループ別に一覧表示する

// 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 = "11112222-3333-4444-5555-666677778888";
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");

サブスクリプションごとにすべての Email Communication Services リソースを一覧表示する

// 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 = "11112222-3333-4444-5555-666677778888";
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 = "11112222-3333-4444-5555-666677778888";
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");

Note

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

前提条件

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

Email Communication Services リソースを作成するには、次のコマンドを使用して資格情報を提供することで 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 のリソースを構成できます。

  • リソース グループ
  • Email Communication Services リソースの名前
  • リソースが関連付けられる地理的な場所

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

Email Communication Services のリソースを管理する

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 Services リソースをすべて一覧表示するには、次のコマンドを使用します:

PS C:\> Get-AzEmailService -SubscriptionId SubscriptionID

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

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

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

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

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

Note

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

次のステップ