chore: change the email header

This commit is contained in:
mahyargdz
2025-07-16 09:47:38 +03:30
parent 2e898050ec
commit db66431a5f
3 changed files with 14 additions and 23 deletions
+4 -4
View File
@@ -108,10 +108,10 @@ export class EmailEnvelopeDto {
//######################################################## //########################################################
export class SendEmailDto { export class SendEmailDto {
@IsNotEmpty({ message: EmailMessage.FROM_ADDRESS_REQUIRED }) // @IsNotEmpty({ message: EmailMessage.FROM_ADDRESS_REQUIRED })
@ValidateNested() // @ValidateNested()
@Type(() => EmailRecipientDto) // @Type(() => EmailRecipientDto)
@ApiProperty({ description: "Address for the From: header" }) // @ApiProperty({ description: "Address for the From: header" })
from: EmailRecipientDto; from: EmailRecipientDto;
@IsOptional() @IsOptional()
+2 -8
View File
@@ -8,7 +8,6 @@ import { SearchMessagesQueryDto } from "./DTO/email-query.dto";
import { SendEmailDto, UpdateDraftDto } from "./DTO/send-email.dto"; import { SendEmailDto, UpdateDraftDto } from "./DTO/send-email.dto";
import { EmailService } from "./services/email.service"; import { EmailService } from "./services/email.service";
import { AuthGuards } from "../../common/decorators/auth-guard.decorator"; import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
import { BusinessDec } from "../../common/decorators/business.decorator";
import { UserDec } from "../../common/decorators/user.decorator"; import { UserDec } from "../../common/decorators/user.decorator";
@AuthGuards() @AuthGuards()
@@ -25,13 +24,8 @@ export class EmailController {
@ApiResponse({ status: 201, description: "Email sent successfully" }) @ApiResponse({ status: 201, description: "Email sent successfully" })
@ApiResponse({ status: 400, description: "Invalid email data or missing required fields for email type" }) @ApiResponse({ status: 400, description: "Invalid email data or missing required fields for email type" })
@ApiResponse({ status: 403, description: "Not authorized to send email" }) @ApiResponse({ status: 403, description: "Not authorized to send email" })
sendEmail( sendEmail(@UserDec("wildduckUserId") userEmailId: string, @UserDec("id") userId: string, @Body() sendEmailDto: SendEmailDto) {
@UserDec("wildduckUserId") userEmailId: string, return this.emailService.sendEmail(userEmailId, userId, sendEmailDto);
@BusinessDec("id") businessId: string,
@UserDec("id") userId: string,
@Body() sendEmailDto: SendEmailDto,
) {
return this.emailService.sendEmail(userEmailId, businessId, userId, sendEmailDto);
} }
@Get("status/:queueId") @Get("status/:queueId")
+8 -11
View File
@@ -30,35 +30,32 @@ export class EmailService {
) {} ) {}
//######################################################## //########################################################
async sendEmail(userEmailId: string, businessId: string, userId: string, sendEmailDto: SendEmailDto) { async sendEmail(userEmailId: string, userId: string, sendEmailDto: SendEmailDto) {
this.logger.log(`Sending ${EmailType.GENERAL} email from user ${userEmailId} to ${sendEmailDto.to.map((t) => t.address).join(", ")}`); this.logger.log(`Sending ${EmailType.GENERAL} email from user ${userEmailId} to ${sendEmailDto.to.map((t) => t.address).join(", ")}`);
try { try {
this.logger.log(`Processing email through business template for business: ${businessId}`); const user = await this.userRepository.findOne({ wildduckUserId: userEmailId, deletedAt: null }, { populate: ["business"] });
if (!user) throw new BadRequestException(EmailMessage.USER_NOT_FOUND);
this.logger.log(`Processing email through business template for business: ${user.business.id}`);
// Process email content through business template const processedTemplate = await this.templateProcessorService.processEmailContent(user.business.id, userId, {
const processedTemplate = await this.templateProcessorService.processEmailContent(businessId, userId, {
text: sendEmailDto.text, text: sendEmailDto.text,
html: sendEmailDto.html, html: sendEmailDto.html,
subject: sendEmailDto.subject, subject: sendEmailDto.subject,
}); });
// Update the DTO with processed content
if (processedTemplate.isHtml) { if (processedTemplate.isHtml) {
sendEmailDto.html = processedTemplate.content; sendEmailDto.html = processedTemplate.content;
sendEmailDto.text = undefined; // Clear text when using HTML template sendEmailDto.text = undefined;
} else { } else {
sendEmailDto.text = processedTemplate.content; sendEmailDto.text = processedTemplate.content;
sendEmailDto.html = undefined; // Clear HTML when no template sendEmailDto.html = undefined;
} }
if (processedTemplate.hasTemplate) { if (processedTemplate.hasTemplate) {
this.logger.log(`Email content processed through template for business: ${businessId}`); this.logger.log(`Email content processed through template for business: ${user.business.id}`);
} }
const user = await this.userRepository.findOne({ wildduckUserId: userEmailId, deletedAt: null, business: { id: businessId } });
if (!user) throw new BadRequestException(EmailMessage.USER_NOT_FOUND);
sendEmailDto.from = { sendEmailDto.from = {
address: user.emailAddress, address: user.emailAddress,
name: user.displayName, name: user.displayName,