Skip to content

The open alternative to Salesforce, designed for AI.

Stop deleting provider domains Twenty did not create (#28914)

neo7734c48997ee708
diff --git a/packages/twenty-server/src/engine/core-modules/emailing-domain/drivers/aws-ses/constants/aws-ses-tenant-tag-key.constant.ts b/packages/twenty-server/src/engine/core-modules/emailing-domain/drivers/aws-ses/constants/aws-ses-tenant-tag-key.constant.ts
new file mode 100644
index 00000000000..b2a13899db5
--- /dev/null
+++ b/packages/twenty-server/src/engine/core-modules/emailing-domain/drivers/aws-ses/constants/aws-ses-tenant-tag-key.constant.ts
@@ -0,0 +1 @@
+export const AWS_SES_TENANT_TAG_KEY = 'Tenant';
diff --git a/packages/twenty-server/src/engine/core-modules/emailing-domain/drivers/aws-ses/services/aws-ses-driver.service.ts b/packages/twenty-server/src/engine/core-modules/emailing-domain/drivers/aws-ses/services/aws-ses-driver.service.ts
index 9d921ea4e1a..92c8d694d6c 100644
--- a/packages/twenty-server/src/engine/core-modules/emailing-domain/drivers/aws-ses/services/aws-ses-driver.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/emailing-domain/drivers/aws-ses/services/aws-ses-driver.service.ts
@@ -28,6 +28,7 @@ import { getUnsubscribeBaseUrl } from 'src/engine/core-modules/emailing-domain/d
import { type UnsubscribeContentService } from 'src/engine/core-modules/emailing-domain/services/unsubscribe-content.service';
import { AWS_SES_RESOURCE_NAME_PREFIX } from 'src/engine/core-modules/emailing-domain/drivers/aws-ses/constants/aws-ses-resource-name-prefix.constant';
+import { AWS_SES_TENANT_TAG_KEY } from 'src/engine/core-modules/emailing-domain/drivers/aws-ses/constants/aws-ses-tenant-tag-key.constant';
import { buildAwsSesVerificationRecords } from 'src/engine/core-modules/emailing-domain/drivers/aws-ses/utils/build-aws-ses-verification-records.util';
import { type AwsSesClientProvider } from 'src/engine/core-modules/emailing-domain/drivers/aws-ses/providers/aws-ses-client.provider';
import { type AwsSesAccountService } from 'src/engine/core-modules/emailing-domain/drivers/aws-ses/services/aws-ses-account.service';
@@ -206,6 +207,27 @@ export class AwsSesDriver implements EmailingDomainDriverInterface {
if (!(error instanceof NotFoundException)) throw error;
});
+ const identity = await sesClient
+ .send(new GetEmailIdentityCommand({ EmailIdentity: input.domain }))
+ .catch((error) => {
+ if (!(error instanceof NotFoundException)) throw error;
+
+ return null;
+ });
+
+ const isCreatedForTenant =
+ identity?.Tags?.some(
+ (tag) => tag.Key === AWS_SES_TENANT_TAG_KEY && tag.Value === tenantName,
+ ) ?? false;
+
+ if (!isCreatedForTenant) {
+ this.logger.log(
+ `Keeping SES identity ${input.domain}: it was not created for tenant ${tenantName}`,
+ );
+
+ return;
+ }
+
await sesClient
.send(new DeleteEmailIdentityCommand({ EmailIdentity: input.domain }))
.catch((error) => {
@@ -319,7 +341,7 @@ export class AwsSesDriver implements EmailingDomainDriverInterface {
const createCommand = new CreateEmailIdentityCommand({
EmailIdentity: domain,
- Tags: [{ Key: 'Tenant', Value: tenantName }],
+ Tags: [{ Key: AWS_SES_TENANT_TAG_KEY, Value: tenantName }],
});
const createResponse = await sesClient.send(createCommand);
diff --git a/packages/twenty-server/src/engine/core-modules/emailing-domain/drivers/resend/services/resend-api-client.service.ts b/packages/twenty-server/src/engine/core-modules/emailing-domain/drivers/resend/services/resend-api-client.service.ts
index 4c46922a568..f718ea4b9aa 100644
--- a/packages/twenty-server/src/engine/core-modules/emailing-domain/drivers/resend/services/resend-api-client.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/emailing-domain/drivers/resend/services/resend-api-client.service.ts
@@ -53,10 +53,6 @@ export class ResendApiClientService {
await this.performRequest('POST', `/domains/${domainId}/verify`);
}
- async deleteDomain(domainId: string): Promise<void> {
- await this.performRequest('DELETE', `/domains/${domainId}`);
- }
-
async getSentEmail(emailId: string): Promise<ResendSentEmail> {
return this.requestJson<ResendSentEmail>('GET', `/emails/${emailId}`);
}
diff --git a/packages/twenty-server/src/engine/core-modules/emailing-domain/drivers/resend/services/resend-driver.service.ts b/packages/twenty-server/src/engine/core-modules/emailing-domain/drivers/resend/services/resend-driver.service.ts
index bbdc34ea474..3287bcba85d 100644
--- a/packages/twenty-server/src/engine/core-modules/emailing-domain/drivers/resend/services/resend-driver.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/emailing-domain/drivers/resend/services/resend-driver.service.ts
@@ -100,21 +100,9 @@ export class ResendDriver implements EmailingDomainDriverInterface {
}
async cleanupDomain(input: EmailingDomainResourceInput): Promise<void> {
- const domain = await this.findDomainByName(input.domain);
-
- if (!isDefined(domain)) {
- return;
- }
-
- await this.resendApiClientService.deleteDomain(domain.id).catch((error) => {
- if (
- error instanceof EmailingDomainDriverException &&
- error.code === EmailingDomainDriverExceptionCode.NOT_FOUND
- ) {
- return;
- }
- throw error;
- });
+ this.logger.log(
+ `Keeping Resend domain ${input.domain}: Resend domains are account-level and may be used by other applications`,
+ );
}
async sendEmail(