chore: add default mailbox for the user
This commit is contained in:
@@ -3,6 +3,7 @@ import { Injectable, Logger } from "@nestjs/common";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { MailServerService } from "../../mail-server/services/mail-server.service";
|
||||
import { MailboxEnum } from "../../mailbox/enums/mailbox.enum";
|
||||
import { Role } from "../../users/entities/role.entity";
|
||||
import { User } from "../../users/entities/user.entity";
|
||||
import { RoleEnum } from "../../users/enums/role.enum";
|
||||
@@ -52,6 +53,33 @@ export class DomainAutomationService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create default mailboxes for a user (Archive and Favorite)
|
||||
*/
|
||||
async createDefaultMailboxes(wildduckUserId: string): Promise<void> {
|
||||
try {
|
||||
const mailboxesToCreate = [
|
||||
{ path: MailboxEnum.ARCHIVE, name: "Archive" },
|
||||
{ path: MailboxEnum.FAVORITE, name: "Favorite" },
|
||||
];
|
||||
|
||||
for (const mailbox of mailboxesToCreate) {
|
||||
try {
|
||||
await firstValueFrom(
|
||||
this.mailServerService.mailboxes.createMailbox(wildduckUserId, {
|
||||
path: mailbox.path,
|
||||
}),
|
||||
);
|
||||
this.logger.log(`Created ${mailbox.name} mailbox for user: ${wildduckUserId}`);
|
||||
} catch (error) {
|
||||
this.logger.warn(`Failed to create ${mailbox.name} mailbox for user ${wildduckUserId}: ${(error as Error).message}`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to create default mailboxes for user ${wildduckUserId}: ${(error as Error).message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create info@domain.com address when domain is verified
|
||||
*/
|
||||
@@ -124,6 +152,9 @@ export class DomainAutomationService {
|
||||
|
||||
await this.em.persistAndFlush(user);
|
||||
|
||||
// Create default mailboxes (Archive and Favorite)
|
||||
await this.createDefaultMailboxes(mailServerUser.id);
|
||||
|
||||
this.logger.log(`Successfully created info address: ${infoEmail} (username: ${uniqueUsername}) for business ${domain.business.name}`);
|
||||
this.logger.log(`Info account credentials - Email: ${infoEmail}, Username: ${uniqueUsername}, Password: [GENERATED]`);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user