Set webhook email sender identity
This commit is contained in:
@@ -319,12 +319,13 @@ HTML;
|
||||
$emailHeaders = "MIME-Version: 1.0\r\n";
|
||||
// Content-type specifies HTML email with UTF-8 character encoding
|
||||
$emailHeaders .= "Content-type: text/html; charset=UTF-8\r\n";
|
||||
// From header sets the sender address to a no-reply address at wh.dixon.cx
|
||||
$emailHeaders .= "From: no-reply@wh.dixon.cx\r\n";
|
||||
|
||||
// Send the email using PHP's built-in mail function
|
||||
// Parameters: recipient, subject, message body, headers
|
||||
$mailSent = mail($email, $subject, $html, $emailHeaders);
|
||||
// Keep both the visible sender and SMTP envelope sender on the public domain.
|
||||
$envelopeSender = 'no-reply@dixon.cx';
|
||||
$emailHeaders .= "From: Webhook Call <$envelopeSender>\r\n";
|
||||
|
||||
// Send the email using PHP's built-in mail function
|
||||
// The -f option prevents sendmail from deriving www-data@<container-hostname>.
|
||||
$mailSent = mail($email, $subject, $html, $emailHeaders, '-f' . $envelopeSender);
|
||||
|
||||
// Check if the email was sent successfully
|
||||
if (!$mailSent) {
|
||||
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
project_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)
|
||||
test_dir=$(mktemp -d)
|
||||
trap 'rm -rf "$test_dir"' EXIT
|
||||
|
||||
sendmail_args="$test_dir/sendmail.args"
|
||||
sendmail_message="$test_dir/sendmail.message"
|
||||
fake_sendmail="$test_dir/sendmail"
|
||||
prepend_file="$test_dir/prepend.php"
|
||||
|
||||
cat > "$fake_sendmail" <<'FAKE_SENDMAIL'
|
||||
#!/usr/bin/env bash
|
||||
printf '%s\n' "$@" > "$MAIL_TEST_ARGS"
|
||||
cat > "$MAIL_TEST_MESSAGE"
|
||||
FAKE_SENDMAIL
|
||||
chmod +x "$fake_sendmail"
|
||||
|
||||
cat > "$prepend_file" <<'PHP'
|
||||
<?php
|
||||
if (!function_exists('getallheaders')) {
|
||||
function getallheaders(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
PHP
|
||||
|
||||
MAIL_TEST_ARGS="$sendmail_args" \
|
||||
MAIL_TEST_MESSAGE="$sendmail_message" \
|
||||
REQUEST_URI='/recipient%40example.com' \
|
||||
REQUEST_METHOD='POST' \
|
||||
REMOTE_ADDR='192.0.2.1' \
|
||||
CONTENT_TYPE='application/json' \
|
||||
php \
|
||||
-d "auto_prepend_file=$prepend_file" \
|
||||
-d "sendmail_path=$fake_sendmail -t -i" \
|
||||
"$project_dir/index.php" >/dev/null
|
||||
|
||||
if ! grep -Fxq -- '-fno-reply@dixon.cx' "$sendmail_args"; then
|
||||
echo 'Expected the envelope sender to be no-reply@dixon.cx.' >&2
|
||||
echo 'Actual sendmail arguments:' >&2
|
||||
sed 's/^/ /' "$sendmail_args" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! grep -Fq $'From: Webhook Call <no-reply@dixon.cx>\r' "$sendmail_message"; then
|
||||
echo 'Expected the From header to be Webhook Call <no-reply@dixon.cx>.' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo 'Mail sender test passed.'
|
||||
Reference in New Issue
Block a user