chore: change the email header
This commit is contained in:
@@ -108,10 +108,10 @@ export class EmailEnvelopeDto {
|
||||
|
||||
//########################################################
|
||||
export class SendEmailDto {
|
||||
@IsNotEmpty({ message: EmailMessage.FROM_ADDRESS_REQUIRED })
|
||||
@ValidateNested()
|
||||
@Type(() => EmailRecipientDto)
|
||||
@ApiProperty({ description: "Address for the From: header" })
|
||||
// @IsNotEmpty({ message: EmailMessage.FROM_ADDRESS_REQUIRED })
|
||||
// @ValidateNested()
|
||||
// @Type(() => EmailRecipientDto)
|
||||
// @ApiProperty({ description: "Address for the From: header" })
|
||||
from: EmailRecipientDto;
|
||||
|
||||
@IsOptional()
|
||||
|
||||
@@ -8,7 +8,6 @@ import { SearchMessagesQueryDto } from "./DTO/email-query.dto";
|
||||
import { SendEmailDto, UpdateDraftDto } from "./DTO/send-email.dto";
|
||||
import { EmailService } from "./services/email.service";
|
||||
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
||||
import { BusinessDec } from "../../common/decorators/business.decorator";
|
||||
import { UserDec } from "../../common/decorators/user.decorator";
|
||||
|
||||
@AuthGuards()
|
||||
@@ -25,13 +24,8 @@ export class EmailController {
|
||||
@ApiResponse({ status: 201, description: "Email sent successfully" })
|
||||
@ApiResponse({ status: 400, description: "Invalid email data or missing required fields for email type" })
|
||||
@ApiResponse({ status: 403, description: "Not authorized to send email" })
|
||||
sendEmail(
|
||||
@UserDec("wildduckUserId") userEmailId: string,
|
||||
@BusinessDec("id") businessId: string,
|
||||
@UserDec("id") userId: string,
|
||||
@Body() sendEmailDto: SendEmailDto,
|
||||
) {
|
||||
return this.emailService.sendEmail(userEmailId, businessId, userId, sendEmailDto);
|
||||
sendEmail(@UserDec("wildduckUserId") userEmailId: string, @UserDec("id") userId: string, @Body() sendEmailDto: SendEmailDto) {
|
||||
return this.emailService.sendEmail(userEmailId, userId, sendEmailDto);
|
||||
}
|
||||
|
||||
@Get("status/:queueId")
|
||||
|
||||
@@ -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(", ")}`);
|
||||
|
||||
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(businessId, userId, {
|
||||
const processedTemplate = await this.templateProcessorService.processEmailContent(user.business.id, userId, {
|
||||
text: sendEmailDto.text,
|
||||
html: sendEmailDto.html,
|
||||
subject: sendEmailDto.subject,
|
||||
});
|
||||
|
||||
// Update the DTO with processed content
|
||||
if (processedTemplate.isHtml) {
|
||||
sendEmailDto.html = processedTemplate.content;
|
||||
sendEmailDto.text = undefined; // Clear text when using HTML template
|
||||
sendEmailDto.text = undefined;
|
||||
} else {
|
||||
sendEmailDto.text = processedTemplate.content;
|
||||
sendEmailDto.html = undefined; // Clear HTML when no template
|
||||
sendEmailDto.html = undefined;
|
||||
}
|
||||
|
||||
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 = {
|
||||
address: user.emailAddress,
|
||||
name: user.displayName,
|
||||
|
||||
Reference in New Issue
Block a user