feat: add configurable sender name and allow users to choose between system and personal SMTP accounts when sending emails
Build and Push Multi-Platform Images / build-and-push (push) Successful in 34s
Build and Push Multi-Platform Images / build-and-push (push) Successful in 34s
This commit is contained in:
@@ -15,6 +15,7 @@ export interface UserSettingsDto {
|
||||
smtpUser: string | null;
|
||||
smtpPassSet: boolean;
|
||||
smtpFrom: string | null;
|
||||
smtpFromName: string | null;
|
||||
mailSignatureHtml: string | null;
|
||||
}
|
||||
|
||||
@@ -75,6 +76,7 @@ export class UserSettingsService {
|
||||
smtpUser?: string | null;
|
||||
smtpPass?: string | null;
|
||||
smtpFrom?: string | null;
|
||||
smtpFromName?: string | null;
|
||||
mailSignatureHtml?: string | null;
|
||||
},
|
||||
): Promise<UserSettingsDto> {
|
||||
@@ -91,6 +93,7 @@ export class UserSettingsService {
|
||||
entity.SmtpPass = this.encrypt(data.smtpPass);
|
||||
}
|
||||
if (data.smtpFrom !== undefined) entity.SmtpFrom = data.smtpFrom;
|
||||
if (data.smtpFromName !== undefined) entity.SmtpFromName = data.smtpFromName;
|
||||
if (data.mailSignatureHtml !== undefined) entity.MailSignatureHtml = data.mailSignatureHtml;
|
||||
|
||||
await this.repo.save(entity);
|
||||
@@ -123,16 +126,34 @@ export class UserSettingsService {
|
||||
} | null> {
|
||||
const entity = await this.repo.findOne({ where: { UserId: userId } });
|
||||
if (!entity?.SmtpHost || !entity?.SmtpPass) return null;
|
||||
const fromEmail = entity.SmtpFrom ?? entity.SmtpUser ?? '';
|
||||
const from = entity.SmtpFromName ? `"${entity.SmtpFromName}" <${fromEmail}>` : fromEmail;
|
||||
return {
|
||||
host: entity.SmtpHost,
|
||||
port: entity.SmtpPort ?? 587,
|
||||
secure: entity.SmtpSecure,
|
||||
user: entity.SmtpUser ?? '',
|
||||
pass: this.decrypt(entity.SmtpPass),
|
||||
from: entity.SmtpFrom ?? entity.SmtpUser ?? '',
|
||||
from,
|
||||
};
|
||||
}
|
||||
|
||||
async getAvailableSenders(userId: string): Promise<{ id: string; label: string }[]> {
|
||||
const defaultEmail = this.configService.get<string>('SMTP_FROM', 'paperless@localhost');
|
||||
const defaultName = this.configService.get<string>('SMTP_FROM_NAME', '');
|
||||
const defaultLabel = defaultName ? `${defaultName} <${defaultEmail}>` : defaultEmail;
|
||||
const senders: { id: string; label: string }[] = [{ id: 'default', label: defaultLabel }];
|
||||
|
||||
const entity = await this.repo.findOne({ where: { UserId: userId } });
|
||||
if (entity?.SmtpHost && entity?.SmtpPass) {
|
||||
const userEmail = entity.SmtpFrom ?? entity.SmtpUser ?? '';
|
||||
const userLabel = entity.SmtpFromName ? `${entity.SmtpFromName} <${userEmail}>` : userEmail;
|
||||
senders.push({ id: 'user', label: userLabel });
|
||||
}
|
||||
|
||||
return senders;
|
||||
}
|
||||
|
||||
private toDto(entity: UserSettings | null): UserSettingsDto {
|
||||
return {
|
||||
smtpHost: entity?.SmtpHost ?? null,
|
||||
@@ -141,6 +162,7 @@ export class UserSettingsService {
|
||||
smtpUser: entity?.SmtpUser ?? null,
|
||||
smtpPassSet: !!(entity?.SmtpPass),
|
||||
smtpFrom: entity?.SmtpFrom ?? null,
|
||||
smtpFromName: entity?.SmtpFromName ?? null,
|
||||
mailSignatureHtml: entity?.MailSignatureHtml ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user