feat(email): add option to set reply-to to creator's email (#159)

* feat(email): add option to set reply-to to creator's email

* style: formatted code
This commit is contained in:
smp46
2026-07-24 18:04:02 +02:00
committed by GitHub
parent 3042f86adc
commit 57704e5943
5 changed files with 44 additions and 19 deletions
+5
View File
@@ -198,6 +198,11 @@ export const configVariables = {
defaultValue: "false",
secret: false,
},
shareRecipientsReplyToCreator: {
type: "boolean",
defaultValue: "false",
secret: false,
},
shareDownloadNotificationSubject: {
type: "string",
defaultValue: "Your file was downloaded",
+32 -18
View File
@@ -14,7 +14,7 @@ export class EmailService {
constructor(
private config: ConfigService,
private readonly i18n: I18nService,
) { }
) {}
private readonly logger = new Logger(EmailService.name);
getTransporter() {
@@ -38,23 +38,28 @@ export class EmailService {
});
}
private async sendMail(email: string, subject: string, text: string) {
const isHtml = this.config.get("email.sendHtmlEmails");
private async sendMail(
email: string,
subject: string,
text: string,
replyTo?: string,
) {
const isHtml = this.config.get("email.sendHtmlEmails");
await this.getTransporter()
.sendMail({
from: `"${this.config.get("general.appName")}" <${this.config.get(
"smtp.email",
)}>`,
to: email,
subject: subject,
[isHtml ? "html" : "text"]: text,
})
.catch((e) => {
this.logger.error(e);
throw new InternalServerErrorException(this.i18n.t("email.sendFailed"));
});
await this.getTransporter()
.sendMail({
from: `"${this.config.get("general.appName")}" <${this.config.get(
"smtp.email",
)}>`,
to: email,
subject: subject,
[isHtml ? "html" : "text"]: text,
...(replyTo && { replyTo }),
})
.catch((e) => {
this.logger.error(e);
throw new InternalServerErrorException(this.i18n.t("email.sendFailed"));
});
}
async sendMailToShareRecipients(
@@ -76,6 +81,14 @@ export class EmailService {
const lang = this.config.get("general.defaultLanguage");
const locale = this.i18n.translate("email.locale", { lang });
let replyTo: string | undefined = undefined;
if (
this.config.get("email.shareRecipientsReplyToCreator") &&
creator?.email
) {
replyTo = `"${creator.username}" <${creator.email}>`;
}
await this.sendMail(
recipientEmail,
this.config.get("email.shareRecipientsSubject"),
@@ -85,7 +98,7 @@ export class EmailService {
.replaceAll(
"{creator}",
creator?.username ??
this.i18n.t("email.shareRecipientsCreatorFallback"),
this.i18n.t("email.shareRecipientsCreatorFallback"),
)
.replaceAll("{creatorEmail}", creator?.email ?? "")
.replaceAll("{shareUrl}", shareUrl)
@@ -99,6 +112,7 @@ export class EmailService {
? moment(expiration).locale(locale).fromNow()
: this.i18n.t("email.shareRecipientsExpiresNeverFallback"),
),
replyTo,
);
}
+1 -1
View File
@@ -165,7 +165,7 @@ export class ShareService {
recipient.email,
recipient.id,
share.id,
share.creator,
share.creator || share.reverseShare?.creator,
share.description,
share.expiration,
);
+2
View File
@@ -121,6 +121,8 @@ email:
Pingvin Share 🐧
#Whether to send an email to the share creator when an email recipient downloads a file. This requires SMTP and email recipient sharing.
enableShareDownloadNotifications: "false"
#Whether to set the Reply-To header to the email address of the user who created the share.
shareRecipientsReplyToCreator: "false"
#Subject of the email which gets sent to the share creator when a recipient downloads a file.
shareDownloadNotificationSubject: Your file was downloaded
#Message which gets sent to the share creator when a recipient downloads a file. Available variables:
+4
View File
@@ -561,6 +561,10 @@ export default {
"admin.config.email.invite-message": "Invite message",
"admin.config.email.invite-message.description":
"Message which gets sent when an admin invites a user. {url} will be replaced with the invite URL, {email} with the email and {password} with the users password.",
"admin.config.email.share-recipients-reply-to-creator":
"Set Reply-To to creator's email",
"admin.config.email.share-recipients-reply-to-creator.description":
"Whether to set the Reply-To header to the email address of the user who created the share.",
"admin.config.email.enable-share-download-notifications":
"Enable download notifications",
"admin.config.email.enable-share-download-notifications.description":