Skip to content

Commit

Permalink
Inherit SMTP server from COmanage CO (CFM-80)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Jan 11, 2026
1 parent 2bb92fe commit 2ad9ce8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ $fields[] = 'required';
var curtypeid = document.getElementById(field);
var typeid = document.getElementById('type-id');

alert(field + ": " + curtypeid.value);
typeid.value = curtypeid.value;
}

Expand Down
3 changes: 3 additions & 0 deletions app/resources/locales/en_US/error.po
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ msgstr "Ooops... Something went wrong."
msgid "setup.co.comanage"
msgstr "Failed to setup COmanage CO"

msgid "smtp_server.none"
msgstr "No outgoing SMTP Server configuration found"

msgid "tree.parent.invalid"
msgstr "The selected {0} is not a valid parent for the current record"

Expand Down
3 changes: 3 additions & 0 deletions app/resources/locales/en_US/field.po
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ msgstr "If set, when sending email only verified Email Addresses of this type (a
msgid "CoSettings.email_smtp_server_id"
msgstr "Outgoing SMTP Server"

msgid "CoSettings.email_smtp_server_id.desc"
msgstr "If a Platform level SMTP Server is set, it will be used when no CO-specific SMTP Server is configured"

msgid "CoSettings.permitted_fields_name"
msgstr "Name Permitted Fields"

Expand Down
12 changes: 9 additions & 3 deletions app/src/Lib/Util/DeliveryUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class DeliveryUtilities {
use \App\Lib\Traits\LabeledLogTrait;

/**
* Send an email to an Address.
* Send an email to an Address. If no Outgoing SMTP Server is configured,
* an InvalidArgumentException will be thrown.
*
* @since COmanage Registry v5.0.0
* @param int $coId CO ID
Expand All @@ -52,8 +53,9 @@ class DeliveryUtilities {
* @param string $cc Addresses to cc
* @param string $bcc Addresses to bcc
* @param string $replyTo Reply-To address to use, instead of the default
* @return bool Returns true if mail was sent, false if no SMTP server was set
* @return bool Returns true if mail was sent
* @throws Cake\Network\Exception\SocketException
* @throws InvalidArgumentException
*/

public static function sendEmailToAddress(
Expand All @@ -78,7 +80,11 @@ public static function sendEmailToAddress(
// No SMTP configured
self::slog('debug', "No Outgoing SMTP Server is configured for CO $coId, so no mail will be sent");

return false;
// Originally we returned false here, but that means the only indication of a missing
// SMTP server configuration is in the error logs, which doesn't seem helpful.
// So we throw an Exception instead, and if the calling code doesn't like that
// it can catch it and do something else.
throw new \InvalidArgumentException(__d('error', 'smtp_server.none'));
}

// Next figure out the recipient
Expand Down
12 changes: 12 additions & 0 deletions app/src/Model/Table/CoSettingsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,18 @@ public function getSmtpServer(int $coId): ?\CoreServer\Model\Entity\SmtpServer {
->firstOrFail();
}

// If this isn't the COmanageCO, then use that configuration, if there is one
$COmanageCO = $this->Cos->find('COmanageCO')->firstOrFail();

if($COmanageCO->id != $coId) {
// Note we're returning an object outside the calling CO's space, which isn't
// expected this shouldn't be a problem ordinarily (core code should know what
// it's doing, and plugins have full access to the database anyway), but there
// could be unidentified edge cases where this could cause problems.

return $this->getSmtpServer($COmanageCO->id);
}

return null;
}

Expand Down

0 comments on commit 2ad9ce8

Please sign in to comment.