import Inject, { RegisterScoped } from "@entity-access/entity-access/dist/di/di.js"; import MailService from "../emails/MailService.js"; import TagService from "../tags/TagService.js"; import Mailbox from "../../model/entities/Mailbox.js"; import EmailAddressService from "../EmailAddressService.js"; import EmailAddress from "../../model/entities/EmailAddress.js"; import SocialMailContext from "../../model/SocialMailContext.js"; import DateTime from "@entity-access/entity-access/dist/types/DateTime.js"; import WebClientService from "../client/WebClientService.js"; @RegisterScoped export default class WelcomeMailService { @Inject mailService: MailService; @Inject tagService: TagService; @Inject emailAddressService: EmailAddressService; @Inject db: SocialMailContext; @Inject wcs?: WebClientService; async sendWelcomeMail(entity: Mailbox, ea: EmailAddress) { if (entity.isChannel || entity.isExternal) { return; } const folderTagID = await this.tagService.getSystemTagID("Contacts"); const senderID = await this.emailAddressService.getId("notifications@esocialmail.com", "Social Mail"); const { mailboxID } = entity; const now = DateTime.now; const htmlBody = await (await this.wcs.getUIPackageInfo()) .downloadText("/content/emails/welcome/welcome.html"); const email = await this.db.emails.statements.insert({ senderName: "Social Mail", subject: "Welcome to Social Mail", senderID, textBody: "", received: true, htmlBody, stateReferencesUpdated: true, statePostReceiveInvoked: true, dateCreated: now, dateReceived: now, dateSent: now, dateUpdated: now, status: "received" }); const { emailID } = email; await this.db.emailRecipients.statements.insert({ emailID, emailAddressID: ea.emailAddressID, type: "to" }); await this.db.mailboxContactEmails.statements.insert({ mailboxID, emailAddressID: senderID, dateReceived: now, emailID, timeRead: now }); await this.db.mailboxContacts.statements.insert({ mailboxID, lastEmailID: email.emailID, emailAddressID: senderID, dateCreated: now, dateUpdated: now, folderTagID }); // await this.mailService.sendNotificationEmail(`welcome-${mailboxID}`, { // from: "social@esocialmail.com", // fromName: "Social Mail", // subject: "Welcome to Social Mail", // textBody: "", // to: ea.emailAddress, // htmlBody // }); } }