From 05b8daede63a4923edb01a9feafc2646885cdc94 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sun, 7 Dec 2025 23:08:08 +0330 Subject: [PATCH] fix : test email : more detail --- EMAIL_BLOCKING_DIAGNOSTIC.md | 51 +++++++++++++++++-- .../email/email-blocking.controller.ts | 24 ++++++++- .../email/services/email-spam.service.ts | 35 +++++++++++++ 3 files changed, 104 insertions(+), 6 deletions(-) diff --git a/EMAIL_BLOCKING_DIAGNOSTIC.md b/EMAIL_BLOCKING_DIAGNOSTIC.md index 90e211a..68db2c7 100644 --- a/EMAIL_BLOCKING_DIAGNOSTIC.md +++ b/EMAIL_BLOCKING_DIAGNOSTIC.md @@ -84,11 +84,52 @@ This endpoint requires **Admin authentication**. Make sure you're authenticated If the domain is not blocked but emails still aren't arriving: -1. Check the sender's email server logs -2. Check WildDuck server logs -3. Verify DNS/MX records for both domains -4. Check if there are any forwarding rules -5. Verify the recipient's email quota isn't exceeded +### Step 1: Check WildDuck Server Logs +Look for SMTP rejection messages, connection attempts, or errors related to the sender domain: +```bash +# Check WildDuck logs for SMTP rejections +grep -i "metixco.ae" /var/log/wildduck/*.log +grep -i "r.sadat@humapek.co" /var/log/wildduck/*.log +``` + +### Step 2: Verify DNS/MX Records +Check that the recipient domain has correct MX records: +```bash +dig MX humapek.co +nslookup -type=MX humapek.co +``` + +### Step 3: Check Sender's Email Server +Ask the sender to: +- Check their email server logs for delivery attempts +- Look for bounce messages or error codes +- Verify the email address is correct: `r.sadat@humapek.co` + +### Step 4: Verify SPF/DKIM/DMARC Records +Check email authentication records: +```bash +# Check SPF record for sender domain +dig TXT metixco.ae | grep -i spf + +# Check DMARC record +dig TXT _dmarc.metixco.ae +``` + +### Step 5: Test with Allowlist +Try adding the domain to allowlist as a test: +```bash +POST /email-blocking/allowlist +{ + "recipientEmail": "r.sadat@humapek.co", + "senderDomain": "metixco.ae", + "description": "Test allowlist for troubleshooting" +} +``` + +### Step 6: Check Firewall/Network +- Verify sender's IP is not blocked by firewall +- Check if there are any network-level restrictions +- Ensure SMTP port (usually 25, 587, or 465) is open ## Example: Fix the Current Issue diff --git a/src/modules/email/email-blocking.controller.ts b/src/modules/email/email-blocking.controller.ts index 2ab18de..7ed94d8 100644 --- a/src/modules/email/email-blocking.controller.ts +++ b/src/modules/email/email-blocking.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Query } from "@nestjs/common"; +import { Body, Controller, Get, Post, Query } from "@nestjs/common"; import { ApiOperation, ApiResponse } from "@nestjs/swagger"; import { EmailSpamService } from "./services/email-spam.service"; @@ -28,4 +28,26 @@ export class EmailBlockingController { const shouldUnblock = unblock === "true" || unblock === "1"; return this.emailSpamService.diagnoseEmailBlocking(recipientEmail, senderDomain, shouldUnblock); } + + @Post("allowlist") + @AdminRoute() + @ApiOperation({ + summary: "Add domain to allowlist (Admin only)", + description: "Add a sender domain to the allowlist for a recipient's business", + }) + @ApiResponse({ status: 200, description: "Domain added to allowlist" }) + @ApiResponse({ status: 400, description: "Invalid parameters" }) + @ApiResponse({ status: 403, description: "Not authorized (Admin only)" }) + async addToAllowlist( + @Body() body: { recipientEmail: string; senderDomain: string; description?: string }, + ) { + if (!body.recipientEmail || !body.senderDomain) { + throw new Error("Both recipientEmail and senderDomain are required"); + } + return this.emailSpamService.addDomainToAllowlistForUser( + body.recipientEmail, + body.senderDomain, + body.description, + ); + } } diff --git a/src/modules/email/services/email-spam.service.ts b/src/modules/email/services/email-spam.service.ts index ef0e1a4..7b93c12 100644 --- a/src/modules/email/services/email-spam.service.ts +++ b/src/modules/email/services/email-spam.service.ts @@ -508,4 +508,39 @@ export class EmailSpamService { return result; } + + //============================================== + /** + * Add domain to allowlist for a specific user's business + */ + async addDomainToAllowlistForUser(recipientEmail: string, senderDomain: string, description?: string) { + this.logger.log(`Adding domain ${senderDomain} to allowlist for user ${recipientEmail}`); + + // Find user by email + const user = await this.userRepository.findOne({ emailAddress: recipientEmail, deletedAt: null }, { populate: ["business"] }); + + if (!user) { + throw new Error(`User with email ${recipientEmail} not found`); + } + + const domainTag = user.business?.id || "default"; + const finalDescription = description || `Manually allowlisted for ${recipientEmail}`; + + try { + const result = await this.addDomainToAllowlist(senderDomain, finalDescription, domainTag); + this.logger.log(`Successfully added ${senderDomain} to allowlist for domain tag: ${domainTag}`); + + return { + success: true, + message: `Domain ${senderDomain} has been added to allowlist for ${recipientEmail}`, + domainTag, + domain: senderDomain, + description: finalDescription, + result, + }; + } catch (error) { + this.logger.error(`Failed to add domain to allowlist: ${error instanceof Error ? error.message : "Unknown error"}`); + throw error; + } + } }