0
Fork 0
mirror of https://github.com/stonith404/pingvin-share.git synced 2025-01-29 01:28:59 -05:00

feat: allow smpt without username and password

This commit is contained in:
Elias Schneider 2024-09-14 17:24:19 +02:00
parent 347026b6d3
commit 8b3e28bac8
No known key found for this signature in database
GPG key ID: 07E623B294202B6C

View file

@ -17,17 +17,18 @@ export class EmailService {
if (!this.config.get("smtp.enabled")) if (!this.config.get("smtp.enabled"))
throw new InternalServerErrorException("SMTP is disabled"); throw new InternalServerErrorException("SMTP is disabled");
const username = this.config.get("smtp.username");
const password = this.config.get("smtp.password");
return nodemailer.createTransport({ return nodemailer.createTransport({
host: this.config.get("smtp.host"), host: this.config.get("smtp.host"),
port: this.config.get("smtp.port"), port: this.config.get("smtp.port"),
secure: this.config.get("smtp.port") == 465, secure: this.config.get("smtp.port") == 465,
auth: { auth:
user: this.config.get("smtp.username"), username || password ? { user: username, pass: password } : undefined,
pass: this.config.get("smtp.password"),
},
tls: { tls: {
rejectUnauthorized: !this.config.get( rejectUnauthorized: !this.config.get(
"smtp.allowUnauthorizedCertificates", "smtp.allowUnauthorizedCertificates"
), ),
}, },
}); });
@ -37,7 +38,7 @@ export class EmailService {
await this.getTransporter() await this.getTransporter()
.sendMail({ .sendMail({
from: `"${this.config.get("general.appName")}" <${this.config.get( from: `"${this.config.get("general.appName")}" <${this.config.get(
"smtp.email", "smtp.email"
)}>`, )}>`,
to: email, to: email,
subject, subject,
@ -54,7 +55,7 @@ export class EmailService {
shareId: string, shareId: string,
creator?: User, creator?: User,
description?: string, description?: string,
expiration?: Date, expiration?: Date
) { ) {
if (!this.config.get("email.enableShareEmailRecipients")) if (!this.config.get("email.enableShareEmailRecipients"))
throw new InternalServerErrorException("Email service disabled"); throw new InternalServerErrorException("Email service disabled");
@ -74,8 +75,8 @@ export class EmailService {
"{expires}", "{expires}",
moment(expiration).unix() != 0 moment(expiration).unix() != 0
? moment(expiration).fromNow() ? moment(expiration).fromNow()
: "in: never", : "in: never"
), )
); );
} }
@ -88,13 +89,13 @@ export class EmailService {
this.config this.config
.get("email.reverseShareMessage") .get("email.reverseShareMessage")
.replaceAll("\\n", "\n") .replaceAll("\\n", "\n")
.replaceAll("{shareUrl}", shareUrl), .replaceAll("{shareUrl}", shareUrl)
); );
} }
async sendResetPasswordEmail(recipientEmail: string, token: string) { async sendResetPasswordEmail(recipientEmail: string, token: string) {
const resetPasswordUrl = `${this.config.get( const resetPasswordUrl = `${this.config.get(
"general.appUrl", "general.appUrl"
)}/auth/resetPassword/${token}`; )}/auth/resetPassword/${token}`;
await this.sendMail( await this.sendMail(
@ -103,7 +104,7 @@ export class EmailService {
this.config this.config
.get("email.resetPasswordMessage") .get("email.resetPasswordMessage")
.replaceAll("\\n", "\n") .replaceAll("\\n", "\n")
.replaceAll("{url}", resetPasswordUrl), .replaceAll("{url}", resetPasswordUrl)
); );
} }
@ -117,7 +118,7 @@ export class EmailService {
.get("email.inviteMessage") .get("email.inviteMessage")
.replaceAll("{url}", loginUrl) .replaceAll("{url}", loginUrl)
.replaceAll("{password}", password) .replaceAll("{password}", password)
.replaceAll("{email}", recipientEmail), .replaceAll("{email}", recipientEmail)
); );
} }
@ -125,7 +126,7 @@ export class EmailService {
await this.getTransporter() await this.getTransporter()
.sendMail({ .sendMail({
from: `"${this.config.get("general.appName")}" <${this.config.get( from: `"${this.config.get("general.appName")}" <${this.config.get(
"smtp.email", "smtp.email"
)}>`, )}>`,
to: recipientEmail, to: recipientEmail,
subject: "Test email", subject: "Test email",