Skip to content

Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.

Added option to set From email on smtp settings

ellite0b6246b09db6
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5f738b1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/db/
+/images/uploads/logos/
\ No newline at end of file
diff --git a/endpoints/cronjobs/sendnotifications.php b/endpoints/cronjobs/sendnotifications.php
index 9dadd13..1632f83 100644
--- a/endpoints/cronjobs/sendnotifications.php
+++ b/endpoints/cronjobs/sendnotifications.php
@@ -16,6 +16,7 @@
$smtpPort = $row["smtp_port"];
$smtpUsername = $row["smtp_username"];
$smtpPassword = $row["smtp_password"];
+ $fromEmail = $row["fromEmail"] ?? "[email protected]";
} else {
echo "Notifications are disabled. No need to run.";
}
@@ -70,7 +71,7 @@
$email = $user['email'];
$name = $user['username'];
- $mail->setFrom('[email protected]', 'Wallos App');
+ $mail->setFrom($fromEmail, 'Wallos App');
$mail->addAddress($email, $name);
$mail->Subject = 'Wallos Notification';
diff --git a/endpoints/db/migrate.php b/endpoints/db/migrate.php
index b4a9b9b..cb65f69 100644
--- a/endpoints/db/migrate.php
+++ b/endpoints/db/migrate.php
@@ -30,6 +30,9 @@ if ($migrationTableExists) {
}
$allMigrations = glob('migrations/*.php');
+if (count($allMigrations) == 0) {
+ $allMigrations = glob('../../migrations/*.php');
+}
$requiredMigrations = array_diff($allMigrations, $completedMigrations);
if (count($requiredMigrations) === 0) {
diff --git a/endpoints/notifications/save.php b/endpoints/notifications/save.php
index de52543..8995205 100644
--- a/endpoints/notifications/save.php
+++ b/endpoints/notifications/save.php
@@ -15,7 +15,7 @@
) {
$response = [
"success" => false,
- "errorMessage" => "Please fill all fields"
+ "errorMessage" => "Please fill all mandatory fields"
];
echo json_encode($response);
} else {
@@ -25,6 +25,7 @@
$smtpPort = $data["smtpport"];
$smtpUsername = $data["smtpusername"];
$smtpPassword = $data["smtppassword"];
+ $fromEmail = $data["fromemail"];
$query = "SELECT COUNT(*) FROM notifications";
$result = $db->querySingle($query);
@@ -37,12 +38,12 @@
echo json_encode($response);
} else {
if ($result == 0) {
- $query = "INSERT INTO notifications (enabled, days, smtp_address, smtp_port, smtp_username, smtp_password)
- VALUES (:enabled, :days, :smtpAddress, :smtpPort, :smtpUsername, :smtpPassword)";
+ $query = "INSERT INTO notifications (enabled, days, smtp_address, smtp_port, smtp_username, smtp_password, from_email)
+ VALUES (:enabled, :days, :smtpAddress, :smtpPort, :smtpUsername, :smtpPassword, :fromEmail)";
} else {
$query = "UPDATE notifications
SET enabled = :enabled, days = :days, smtp_address = :smtpAddress, smtp_port = :smtpPort,
- smtp_username = :smtpUsername, smtp_password = :smtpPassword";
+ smtp_username = :smtpUsername, smtp_password = :smtpPassword, from_email = :fromEmail";
}
$stmt = $db->prepare($query);
@@ -52,6 +53,7 @@
$stmt->bindValue(':smtpPort', $smtpPort, SQLITE3_INTEGER);
$stmt->bindValue(':smtpUsername', $smtpUsername, SQLITE3_TEXT);
$stmt->bindValue(':smtpPassword', $smtpPassword, SQLITE3_TEXT);
+ $stmt->bindValue(':fromEmail', $fromEmail, SQLITE3_TEXT);
if ($stmt->execute()) {
$response = [
diff --git a/endpoints/notifications/sendtestmail.php b/endpoints/notifications/sendtestmail.php
index 239d7f6..1462544 100644
--- a/endpoints/notifications/sendtestmail.php
+++ b/endpoints/notifications/sendtestmail.php
@@ -31,6 +31,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
$smtpPort = $data["smtpport"];
$smtpUsername = $data["smtpusername"];
$smtpPassword = $data["smtppassword"];
+ $fromEmail = $data["fromEmail"] ?? "[email protected]";
$mail = new PHPMailer(true);
$mail->isSMTP();
@@ -47,7 +48,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
$email = $user['email'];
$name = $user['username'];
- $mail->setFrom('[email protected]', 'Wallos App');
+ $mail->setFrom($fromEmail, 'Wallos App');
$mail->addAddress($email, $name);
$mail->Subject = 'Wallos Notification';
diff --git a/migrations/000003.php b/migrations/000003.php
new file mode 100644
index 0000000..90d127f
--- /dev/null
+++ b/migrations/000003.php
@@ -0,0 +1,10 @@
+<?php
+// This migration adds a "from_email" column to the notifications table.
+
+/** @noinspection PhpUndefinedVariableInspection */
+$columnQuery = $db->query("SELECT * FROM pragma_table_info('notifications') where name='from_email'");
+$columnRequired = $columnQuery->fetchArray(SQLITE3_ASSOC) === false;
+
+if ($columnRequired) {
+ $db->exec('ALTER TABLE notifications ADD COLUMN from_email VARCHAR(255);');
+}
diff --git a/scripts/settings.js b/scripts/settings.js
index 5ae2935..ae30258 100644
--- a/scripts/settings.js
+++ b/scripts/settings.js
@@ -507,6 +507,7 @@ function saveNotificationsButton() {
const smtpPort = document.getElementById("smtpport").value;
const smtpUsername = document.getElementById("smtpusername").value;
const smtpPassword = document.getElementById("smtppassword").value;
+ const fromEmail = document.getElementById("fromemail").value;
const data = {
enabled: enabled,
@@ -514,7 +515,8 @@ function saveNotificationsButton() {
smtpaddress: smtpAddress,
smtpport: smtpPort,
smtpusername: smtpUsername,
- smtppassword: smtpPassword
+ smtppassword: smtpPassword,
+ fromemail: fromEmail
};
fetch('/endpoints/notifications/save.php', {
@@ -547,12 +549,14 @@ function testNotificationButton() {
const smtpPort = document.getElementById("smtpport").value;
const smtpUsername = document.getElementById("smtpusername").value;
const smtpPassword = document.getElementById("smtppassword").value;
+ const fromEmail = document.getElementById("fromemail").value;
const data = {
smtpaddress: smtpAddress,
smtpport: smtpPort,
smtpusername: smtpUsername,
- smtppassword: smtpPassword
+ smtppassword: smtpPassword,
+ fromemail: fromEmail
};
fetch('/endpoints/notifications/sendtestmail.php', {
diff --git a/settings.php b/settings.php
index 6b9a918..1ff04ed 100644
--- a/settings.php
+++ b/settings.php
@@ -151,6 +151,7 @@
$notifications['smtp_port'] = "";
$notifications['smtp_username'] = "";
$notifications['smtp_password'] = "";
+ $notifications['from_email'] = "";
}
?>
@@ -190,6 +191,9 @@
<div class="form-group-inline">
<input type="password" name="smtppassword" id="smtppassword" placeholder="SMTP Password" value="<?= $notifications['smtp_password'] ?>" />
</div>
+ <div class="form-group-inline">
+ <input type="text" name="fromemail" id="fromemail" placeholder="From email (Optional)" value="<?= $notifications['from_email'] || "" ?>" />
+ </div>
<div class="settings-notes">
<p>
<i class="fa-solid fa-circle-info"></i> SMTP Password is transmitted and stored in plaintext.