Skip to content

Commit cad415d

Browse files
author
Jill Grant
authored
Merge pull request #259382 from yogeshmo/user/ymohanraj/adding-suppression-list-quickstart
Adding quickstarts for email suppression list management
2 parents 0716c23 + 6493b4b commit cad415d

File tree

6 files changed

+578
-0
lines changed

6 files changed

+578
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
---
2+
title: include file
3+
description: include file
4+
author: yogeshmo
5+
manager: koagbakp
6+
services: azure-communication-services
7+
ms.author: yogeshmo
8+
ms.date: 11/21/2023
9+
ms.topic: include
10+
ms.service: azure-communication-services
11+
ms.custom: mode-other
12+
---
13+
14+
## Prerequisites
15+
16+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/dotnet/).
17+
- An Azure Email Communication Services Resource ready to provision domains. [Get started creating an Email Communication Resource](../create-email-communication-resource.md).
18+
- An [Azure Managed Domain](../add-azure-managed-domains.md) or [Custom Domain](../add-custom-verified-domains.md) provisioned and ready to send emails.
19+
- We're using a [service principal for authentication](../../../../active-directory/develop/howto-create-service-principal-portal.md). Set the values of the client ID, tenant ID, and client secret of the Azure Active Directory (AD) application as the following environment variables: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, and `AZURE_CLIENT_SECRET`.
20+
21+
## Install the required packages
22+
23+
Add the following dependencies to your `pom.xml`.
24+
25+
```
26+
<dependency>
27+
<groupId>com.azure.resourcemanager</groupId>
28+
<artifactId>azure-resourcemanager-communication</artifactId>
29+
<version>2.2.0</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.azure</groupId>
33+
<artifactId>azure-identity</artifactId>
34+
<version>1.11.1</version>
35+
</dependency>
36+
```
37+
38+
39+
## Initialize the management client
40+
41+
Set the environment variable `AZURE_SUBSCRIPTION_ID` with the subscription ID of the subscription your Domain and Email resources are in.
42+
43+
Add the following imports at the top of your file.
44+
45+
```java
46+
import com.azure.core.credential.TokenCredential;
47+
import com.azure.core.management.AzureEnvironment;
48+
import com.azure.core.management.profile.AzureProfile;
49+
import com.azure.identity.DefaultAzureCredentialBuilder;
50+
import com.azure.resourcemanager.communication.CommunicationManager;
51+
```
52+
53+
Run the code sample to initialize the management client.
54+
55+
```java
56+
AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
57+
TokenCredential credential = new DefaultAzureCredentialBuilder()
58+
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
59+
.build();
60+
61+
CommunicationManager manager = CommunicationManager
62+
.authenticate(credential, profile);
63+
```
64+
65+
## Add a suppression list to a domain resource
66+
67+
To block your email messages from being sent to certain addresses, the first step is setting up a suppression list in your domain resource.
68+
69+
Update the code sample with the resource group name, the email service name, and the domain resource name for which you would like to create the suppression list. Find this information in the portal by navigating to the domain resource you created when setting up the prerequisites. The title of the resource is `<your-email-service-name>/<your-domain-name>`. Find the resource group name and subscription ID in the Essentials sections in the domain resource overview. Choose any name for your suppression list resource and update that field in the sample as well.
70+
71+
For the list name, make sure it's the same as the sender username of the MailFrom address you would like to suppress emails from. These MailFrom addresses can be found in the "MailFrom addresses" section of your domain resource in the portal. For example, you may have a MailFrom address that looks like "[email protected]". The sender username for this address would be "donotreply" so a list name of "donotreply" should be used.
72+
73+
```java
74+
String resourceGroupName = "<your-resource-group-name>"; // Found in the essentials section of the domain resource portal overview
75+
String emailServiceName = "<your-email-service-name>"; // Found in the first part of the portal domain resource title
76+
String domainResourceName = "<your-domain-name>"; // Found in the second part of the portal domain resource title
77+
String suppressionListResourceName = "<your-suppression-list-resource-name>";
78+
79+
manager.suppressionLists().define(suppressionListResourceName)
80+
.withExistingDomain(resourceGroupName, emailServiceName, domainResourceName)
81+
.withListName("<your-sender-username>") // Should match the sender username of the MailFrom address you would like to suppress emails from
82+
.create();
83+
```
84+
85+
If you would like to suppress emails from all the sender usernames in particular domain, you can pass in an empty string for the list name.
86+
87+
```java
88+
manager.suppressionLists().define(suppressionListResourceName)
89+
.withExistingDomain(resourceGroupName, emailServiceName, domainResourceName)
90+
.withListName("")
91+
.create();
92+
```
93+
94+
## Add an address to a suppression list
95+
96+
After setting up the suppression list, you can now add specific email addresses to which you wish to prevent your email messages from being sent.
97+
98+
Update the code sample with the suppression list address ID. Every suppression list address ID you add needs to be unique. We recommend using a GUID. Update the email address you want to block from receiving your messages as well.
99+
100+
To add multiple addresses to the suppression list, you need to repeat this code sample multiple times.
101+
102+
```java
103+
String suppressionListAddressId = "<your-suppression-list-address-id>";
104+
105+
manager.suppressionListAddresses().define(suppressionListAddressId)
106+
.withExistingSuppressionList(resourceGroupName, emailServiceName, domainResourceName, suppressionListResourceName)
107+
.withEmail("<email-address-to-suppress>") // Should match the email address you would like to block from receiving your messages
108+
.create();
109+
```
110+
111+
You can now try sending an email to the suppressed address from the [`TryEmail` section of your Communication Service resource or by using one of the Email SDKs](../send-email.md). Make sure to send the email using the MailFrom address with the sender username you've chosen to suppress. Your email won't send to the suppressed address.
112+
113+
If you try sending an email from a sender username that is not suppressed the email still successfully sends.
114+
115+
## Remove an address from a suppression list
116+
117+
Call the `delete` method on `suppressionListAddresses` to remove an address from the suppression list.
118+
119+
```java
120+
manager.suppressionListAddresses()
121+
.delete(resourceGroupName, emailServiceName, domainResourceName, suppressionListResourceName, suppressionListAddressId);
122+
```
123+
124+
You can now try sending an email to the suppressed address from the [`TryEmail` section of your Communication Service resource or by using one of the Email SDKs](../send-email.md). Make sure to send the email using the MailFrom address with the sender username you choose to suppress. Your email will successfully send to the previously suppressed address.
125+
126+
## Remove a suppression list from a domain resource
127+
128+
Call the `delete` method on `suppressionLists` to remove a suppression list from the domain resource.
129+
130+
```java
131+
manager.suppressionLists()
132+
.delete(resourceGroupName, emailServiceName, domainResourceName, suppressionListResourceName);
133+
```
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
---
2+
title: include file
3+
description: include file
4+
author: yogeshmo
5+
manager: koagbakp
6+
services: azure-communication-services
7+
ms.author: yogeshmo
8+
ms.date: 11/21/2023
9+
ms.topic: include
10+
ms.service: azure-communication-services
11+
ms.custom: mode-other
12+
---
13+
14+
## Prerequisites
15+
16+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/dotnet/).
17+
- An Azure Email Communication Services Resource ready to provision domains. [Get started creating an Email Communication Resource](../create-email-communication-resource.md).
18+
- An [Azure Managed Domain](../add-azure-managed-domains.md) or [Custom Domain](../add-custom-verified-domains.md) provisioned and ready to send emails.
19+
- We're using a [service principal for authentication](../../../../active-directory/develop/howto-create-service-principal-portal.md). Set the values of the client ID, tenant ID, and client secret of the Azure Active Directory (AD) application as the following environment variables: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, and `AZURE_CLIENT_SECRET`.
20+
21+
## Install the required packages
22+
23+
```console
24+
npm install @azure/arm-communication
25+
npm install @azure/identity
26+
```
27+
28+
29+
## Initialize the management client
30+
31+
Replace the field in the sample code with the subscription ID of the subscription your Domain and Email resources are in. Run the code sample to initialize the management client.
32+
33+
```javascript
34+
const { CommunicationServiceManagementClient } = require("@azure/arm-communication");
35+
const { DefaultAzureCredential } = require("@azure/identity");
36+
37+
const credential = new DefaultAzureCredential();
38+
const subscriptionId = "<your-subscription-id>";
39+
40+
const client = new CommunicationServiceManagementClient(credential, subscriptionId);
41+
```
42+
43+
## Add a suppression list to a domain resource
44+
45+
To block your email messages from being sent to certain addresses, the first step is setting up a suppression list in your domain resource.
46+
47+
Update the code sample with the resource group name, the email service name, and the domain resource name for which you would like to create the suppression list. Find this information in the portal by navigating to the domain resource you created when setting up the prerequisites. The title of the resource is `<your-email-service-name>/<your-domain-name>`. Find the resource group name and subscription ID in the Essentials sections in the domain resource overview. Choose any name for your suppression list resource and update that field in the sample as well.
48+
49+
For the list name, make sure it's the same as the sender username of the MailFrom address you would like to suppress emails from. These MailFrom addresses can be found in the "MailFrom addresses" section of your domain resource in the portal. For example, you may have a MailFrom address that looks like "[email protected]". The sender username for this address would be "donotreply" so a list name of "donotreply" should be used.
50+
51+
```javascript
52+
const resourceGroupName = "<your-resource-group-name>"; // Found in the essentials section of the domain resource portal overview
53+
const emailServiceName = "<your-email-service-name>"; // Found in the first part of the portal domain resource title
54+
const domainResourceName = "<your-domain-name>"; // Found in the second part of the portal domain resource title
55+
const suppressionListResourceName = "<your-suppression-list-resource-name>";
56+
57+
parameters = {
58+
"listName": "<your-sender-username>", // Should match the sender username of the MailFrom address you would like to suppress emails from
59+
}
60+
61+
await client.suppressionLists.createOrUpdate(
62+
resourceGroupName,
63+
emailServiceName,
64+
domainResourceName,
65+
suppressionListResourceName,
66+
parameters
67+
);
68+
```
69+
70+
If you would like to suppress emails from all the sender usernames in particular domain, you can pass in an empty string for the list name.
71+
72+
```javascript
73+
parameters = {
74+
"listName": "",
75+
}
76+
77+
await client.suppressionLists.createOrUpdate(
78+
resourceGroupName,
79+
emailServiceName,
80+
domainResourceName,
81+
suppressionListResourceName,
82+
parameters
83+
);
84+
```
85+
86+
## Add an address to a suppression list
87+
88+
After setting up the suppression list, you can now add specific email addresses to which you wish to prevent your email messages from being sent.
89+
90+
Update the code sample with the suppression list address ID. Every suppression list address ID you add needs to be unique. We recommend using a GUID. Update the email address you want to block from receiving your messages as well.
91+
92+
To add multiple addresses to the suppression list, you need to repeat this code sample multiple times.
93+
94+
```javascript
95+
const suppressionListAddressId = "<your-suppression-list-address-id>";
96+
97+
parameters = {
98+
"email": "<email-address-to-suppress>" // Should match the email address you would like to block from receiving your messages
99+
}
100+
101+
await client.suppressionListAddresses.createOrUpdate(
102+
resourceGroupName,
103+
emailServiceName,
104+
domainResourceName,
105+
suppressionListResourceName,
106+
suppressionListAddressId,
107+
parameters
108+
);
109+
110+
```
111+
112+
You can now try sending an email to the suppressed address from the [`TryEmail` section of your Communication Service resource or by using one of the Email SDKs](../send-email.md). Make sure to send the email using the MailFrom address with the sender username you've chosen to suppress. Your email won't send to the suppressed address.
113+
114+
If you try sending an email from a sender username that is not suppressed the email still successfully sends.
115+
116+
## Remove an address from a suppression list
117+
118+
Call the `delete` method on `suppressionListAddresses` to remove an address from the suppression list.
119+
120+
```javascript
121+
await client.suppressionListAddresses.delete(
122+
resourceGroupName,
123+
emailServiceName,
124+
domainResourceName,
125+
suppressionListResourceName,
126+
suppressionListAddressId
127+
);
128+
```
129+
130+
You can now try sending an email to the suppressed address from the [`TryEmail` section of your Communication Service resource or by using one of the Email SDKs](../send-email.md). Make sure to send the email using the MailFrom address with the sender username you choose to suppress. Your email will successfully send to the previously suppressed address.
131+
132+
## Remove a suppression list from a domain resource
133+
134+
Call the `delete` method on `suppressionList` to remove a suppression list from the domain resource.
135+
136+
```javascript
137+
await client.suppressionLists.delete(
138+
resourceGroupName,
139+
emailServiceName,
140+
domainResourceName,
141+
suppressionListResourceName
142+
);
143+
```

0 commit comments

Comments
 (0)