summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/EmailService.ts
diff options
context:
space:
mode:
authorsyuilo <4439005+syuilo@users.noreply.github.com>2024-09-22 12:53:13 +0900
committerGitHub <noreply@github.com>2024-09-22 12:53:13 +0900
commit023fa30280e561e9921a2c83138af4cac01068ab (patch)
tree9c94734bd7cacdf28a66b9dfc9c4a8c2fb234604 /packages/backend/src/core/EmailService.ts
parent:art: (diff)
downloadsharkey-023fa30280e561e9921a2c83138af4cac01068ab.tar.gz
sharkey-023fa30280e561e9921a2c83138af4cac01068ab.tar.bz2
sharkey-023fa30280e561e9921a2c83138af4cac01068ab.zip
refactor/perf(backend): provide metadata statically (#14601)
* wip * Update ReactionService.ts * Update ApiCallService.ts * Update timeline.ts * Update GlobalModule.ts * Update GlobalModule.ts * Update NoteEntityService.ts * wip * wip * wip * Update ApPersonService.ts * wip * Update GlobalModule.ts * Update mock-resolver.ts * Update RoleService.ts * Update activitypub.ts * Update activitypub.ts * Update activitypub.ts * Update activitypub.ts * Update activitypub.ts * clean up * Update utils.ts * Update UtilityService.ts * Revert "Update utils.ts" This reverts commit a27d4be764b78c1b5a9eac685e261fee49331d89. * Revert "Update UtilityService.ts" This reverts commit e5fd9e004c482cf099252201c0c1aa888e001430. * vuwa- * Revert "vuwa-" This reverts commit 0c3bd12472b4b9938cdff2d6f131e6800bc3724c. * Update entry.ts * Update entry.ts * Update entry.ts * Update entry.ts * Update jest.setup.ts
Diffstat (limited to 'packages/backend/src/core/EmailService.ts')
-rw-r--r--packages/backend/src/core/EmailService.ts43
1 files changed, 19 insertions, 24 deletions
diff --git a/packages/backend/src/core/EmailService.ts b/packages/backend/src/core/EmailService.ts
index 37fa58bb65..a176474b95 100644
--- a/packages/backend/src/core/EmailService.ts
+++ b/packages/backend/src/core/EmailService.ts
@@ -8,16 +8,14 @@ import * as nodemailer from 'nodemailer';
import juice from 'juice';
import { Inject, Injectable } from '@nestjs/common';
import { validate as validateEmail } from 'deep-email-validator';
-import { MetaService } from '@/core/MetaService.js';
import { UtilityService } from '@/core/UtilityService.js';
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
import type Logger from '@/logger.js';
-import type { UserProfilesRepository } from '@/models/_.js';
+import type { MiMeta, UserProfilesRepository } from '@/models/_.js';
import { LoggerService } from '@/core/LoggerService.js';
import { bindThis } from '@/decorators.js';
import { HttpRequestService } from '@/core/HttpRequestService.js';
-import { QueueService } from '@/core/QueueService.js';
@Injectable()
export class EmailService {
@@ -27,38 +25,37 @@ export class EmailService {
@Inject(DI.config)
private config: Config,
+ @Inject(DI.meta)
+ private meta: MiMeta,
+
@Inject(DI.userProfilesRepository)
private userProfilesRepository: UserProfilesRepository,
- private metaService: MetaService,
private loggerService: LoggerService,
private utilityService: UtilityService,
private httpRequestService: HttpRequestService,
- private queueService: QueueService,
) {
this.logger = this.loggerService.getLogger('email');
}
@bindThis
public async sendEmail(to: string, subject: string, html: string, text: string) {
- const meta = await this.metaService.fetch(true);
-
- if (!meta.enableEmail) return;
+ if (!this.meta.enableEmail) return;
const iconUrl = `${this.config.url}/static-assets/mi-white.png`;
const emailSettingUrl = `${this.config.url}/settings/email`;
- const enableAuth = meta.smtpUser != null && meta.smtpUser !== '';
+ const enableAuth = this.meta.smtpUser != null && this.meta.smtpUser !== '';
const transporter = nodemailer.createTransport({
- host: meta.smtpHost,
- port: meta.smtpPort,
- secure: meta.smtpSecure,
+ host: this.meta.smtpHost,
+ port: this.meta.smtpPort,
+ secure: this.meta.smtpSecure,
ignoreTLS: !enableAuth,
proxy: this.config.proxySmtp,
auth: enableAuth ? {
- user: meta.smtpUser,
- pass: meta.smtpPass,
+ user: this.meta.smtpUser,
+ pass: this.meta.smtpPass,
} : undefined,
} as any);
@@ -127,7 +124,7 @@ export class EmailService {
<body>
<main>
<header>
- <img src="${ meta.logoImageUrl ?? meta.iconUrl ?? iconUrl }"/>
+ <img src="${ this.meta.logoImageUrl ?? this.meta.iconUrl ?? iconUrl }"/>
</header>
<article>
<h1>${ subject }</h1>
@@ -148,7 +145,7 @@ export class EmailService {
try {
// TODO: htmlサニタイズ
const info = await transporter.sendMail({
- from: meta.email!,
+ from: this.meta.email!,
to: to,
subject: subject,
text: text,
@@ -167,8 +164,6 @@ export class EmailService {
available: boolean;
reason: null | 'used' | 'format' | 'disposable' | 'mx' | 'smtp' | 'banned' | 'network' | 'blacklist';
}> {
- const meta = await this.metaService.fetch();
-
const exist = await this.userProfilesRepository.countBy({
emailVerified: true,
email: emailAddress,
@@ -186,11 +181,11 @@ export class EmailService {
reason?: string | null,
} = { valid: true, reason: null };
- if (meta.enableActiveEmailValidation) {
- if (meta.enableVerifymailApi && meta.verifymailAuthKey != null) {
- validated = await this.verifyMail(emailAddress, meta.verifymailAuthKey);
- } else if (meta.enableTruemailApi && meta.truemailInstance && meta.truemailAuthKey != null) {
- validated = await this.trueMail(meta.truemailInstance, emailAddress, meta.truemailAuthKey);
+ if (this.meta.enableActiveEmailValidation) {
+ if (this.meta.enableVerifymailApi && this.meta.verifymailAuthKey != null) {
+ validated = await this.verifyMail(emailAddress, this.meta.verifymailAuthKey);
+ } else if (this.meta.enableTruemailApi && this.meta.truemailInstance && this.meta.truemailAuthKey != null) {
+ validated = await this.trueMail(this.meta.truemailInstance, emailAddress, this.meta.truemailAuthKey);
} else {
validated = await validateEmail({
email: emailAddress,
@@ -220,7 +215,7 @@ export class EmailService {
}
const emailDomain: string = emailAddress.split('@')[1];
- const isBanned = this.utilityService.isBlockedHost(meta.bannedEmailDomains, emailDomain);
+ const isBanned = this.utilityService.isBlockedHost(this.meta.bannedEmailDomains, emailDomain);
if (isBanned) {
return {