Skip to content

Commit

Permalink
add multi email recipients
Browse files Browse the repository at this point in the history
  • Loading branch information
teschiopol authored Sep 1, 2024
1 parent 8b35c30 commit 0fb8fb2
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 4 deletions.
8 changes: 8 additions & 0 deletions endpoints/cronjobs/sendcancellationnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
$email['smtpUsername'] = $row["smtp_username"];
$email['smtpPassword'] = $row["smtp_password"];
$email['fromEmail'] = $row["from_email"] ? $row["from_email"] : "wallos@wallosapp.com";
$email['otherEmail'] = $row["other_email"];
}

// Check if Discord notifications are enabled and get the settings
Expand Down Expand Up @@ -216,6 +217,13 @@
$mail->setFrom($email['fromEmail'], 'Wallos App');
$mail->addAddress($emailaddress, $name);

if (!empty($email['otherEmail'])) {
$list = explode(';', $email['otherEmail']);
foreach($list as $value) {
$mail->addCC(trim($value));
}
}

$mail->Subject = 'Wallos Cancellation Notification';
$mail->Body = $message;

Expand Down
8 changes: 8 additions & 0 deletions endpoints/cronjobs/sendnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
$email['smtpUsername'] = $row["smtp_username"];
$email['smtpPassword'] = $row["smtp_password"];
$email['fromEmail'] = $row["from_email"] ? $row["from_email"] : "wallos@wallosapp.com";
$email['otherEmail'] = $row["other_email"];
}

// Check if Discord notifications are enabled and get the settings
Expand Down Expand Up @@ -260,6 +261,13 @@
$mail->setFrom($email['fromEmail'], 'Wallos App');
$mail->addAddress($emailaddress, $name);

if (!empty($email['otherEmail'])) {
$list = explode(';', $email['otherEmail']);
foreach($list as $value) {
$mail->addCC(trim($value));
}
}

$mail->Subject = 'Wallos Notification';
$mail->Body = $message;

Expand Down
8 changes: 5 additions & 3 deletions endpoints/notifications/saveemailnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
$smtpUsername = $data["smtpusername"];
$smtpPassword = $data["smtppassword"];
$fromEmail = $data["fromemail"];
$otherEmail = $data["otheremail"];

$query = "SELECT COUNT(*) FROM email_notifications WHERE user_id = :userId";
$stmt = $db->prepare($query);
Expand All @@ -50,12 +51,12 @@
$row = $result->fetchArray();
$count = $row[0];
if ($count == 0) {
$query = "INSERT INTO email_notifications (enabled, smtp_address, smtp_port, smtp_username, smtp_password, from_email, encryption, user_id)
VALUES (:enabled, :smtpAddress, :smtpPort, :smtpUsername, :smtpPassword, :fromEmail, :encryption, :userId)";
$query = "INSERT INTO email_notifications (enabled, smtp_address, smtp_port, smtp_username, smtp_password, from_email, other_email, encryption, user_id)
VALUES (:enabled, :smtpAddress, :smtpPort, :smtpUsername, :smtpPassword, :fromEmail, :otherEmail, :encryption, :userId)";
} else {
$query = "UPDATE email_notifications
SET enabled = :enabled, smtp_address = :smtpAddress, smtp_port = :smtpPort,
smtp_username = :smtpUsername, smtp_password = :smtpPassword, from_email = :fromEmail, encryption = :encryption WHERE user_id = :userId";
smtp_username = :smtpUsername, smtp_password = :smtpPassword, from_email = :fromEmail, other_email = :otherEmail, encryption = :encryption WHERE user_id = :userId";
}

$stmt = $db->prepare($query);
Expand All @@ -65,6 +66,7 @@
$stmt->bindValue(':smtpUsername', $smtpUsername, SQLITE3_TEXT);
$stmt->bindValue(':smtpPassword', $smtpPassword, SQLITE3_TEXT);
$stmt->bindValue(':fromEmail', $fromEmail, SQLITE3_TEXT);
$stmt->bindValue(':otherEmail', $otherEmail, SQLITE3_TEXT);
$stmt->bindValue(':encryption', $encryption, SQLITE3_TEXT);
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);

Expand Down
1 change: 1 addition & 0 deletions includes/i18n/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"smtp_username" => "SMTP Username",
"smtp_password" => "SMTP Password",
"from_email" => "From email (Optional)",
"other_email" => "Other email (Use ; to separate)",
"smtp_info" => "SMTP Password is transmitted and stored in plaintext. For security, please create an account just for this.",
"telegram" => "Telegram",
"telegram_bot_token" => "Telegram Bot Token",
Expand Down
1 change: 1 addition & 0 deletions includes/i18n/it.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
'smtp_username' => 'Nome utente SMTP',
'smtp_password' => 'Password SMTP',
'from_email' => 'Da quale e-mail (Opzionale)',
"other_email" => "Altre e-mail (Usa ; per separare)",
'smtp_info' => 'La password SMTP viene memorizzata e trasmessa in chiaro. Per motivi di sicurezza, si prega di creare un account da utilizzare solo per questo.',
"telegram" => "Telegram",
"telegram_bot_token" => "Telegram Bot Token",
Expand Down
10 changes: 10 additions & 0 deletions migrations/000026.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
// This migration adds a "other_email" column to the email_notifications table.

/** @noinspection PhpUndefinedVariableInspection */
$columnQuery = $db->query("SELECT * FROM pragma_table_info('email_notifications') where name='other_email'");
$columnRequired = $columnQuery->fetchArray(SQLITE3_ASSOC) === false;

if ($columnRequired) {
$db->exec('ALTER TABLE email_notifications ADD COLUMN other_email TEXT DEFAULT "";');
}
4 changes: 3 additions & 1 deletion scripts/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function saveNotificationsEmailButton() {
const smtpUsername = document.getElementById("smtpusername").value;
const smtpPassword = document.getElementById("smtppassword").value;
const fromEmail = document.getElementById("fromemail").value;
const otherEmail = document.getElementById("otheremail").value;

const data = {
enabled: enabled,
Expand All @@ -73,7 +74,8 @@ function saveNotificationsEmailButton() {
encryption: encryption,
smtpusername: smtpUsername,
smtppassword: smtpPassword,
fromemail: fromEmail
fromemail: fromEmail,
otheremail: otherEmail
};

makeFetchCall('endpoints/notifications/saveemailnotifications.php', data, button);
Expand Down
7 changes: 7 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class="thin mobile-grow" />
$notificationsEmail['smtp_username'] = $row['smtp_username'];
$notificationsEmail['smtp_password'] = $row['smtp_password'];
$notificationsEmail['from_email'] = $row['from_email'];
$notificationsEmail['other_email'] = $row['other_email'];
$rowCount++;
}

Expand All @@ -260,6 +261,7 @@ class="thin mobile-grow" />
$notificationsEmail['smtp_username'] = "";
$notificationsEmail['smtp_password'] = "";
$notificationsEmail['from_email'] = "";
$notificationsEmail['other_email'] = "";
}

// Discord notifications
Expand Down Expand Up @@ -481,6 +483,11 @@ class="one-third" value="<?= $notificationsEmail['smtp_port'] ?>" />
placeholder="<?= translate('from_email', $i18n) ?>"
value="<?= $notificationsEmail['from_email'] ?>" />
</div>
<div class="form-group-inline">
<input type="text" name="otheremail" id="otheremail"
placeholder="<?= translate('other_email', $i18n) ?>"
value="<?= $notificationsEmail['other_email'] ?>" />
</div>
<div class="buttons">
<input type="button" class="secondary-button thin mobile-grow"
value="<?= translate('test', $i18n) ?>" id="testNotificationsEmail"
Expand Down

0 comments on commit 0fb8fb2

Please sign in to comment.