Fixed Hard to debug email messages from error log without the from address

Jake B.

Well-known member
Affected version
2.2.8
When using mail services that require each address to be whitelisted separately even when the domain has been allowed (such as SendGrid) it is very hard to debug some errors related to this without knowing the from address being used, since it can be overwritten to use a different email address for things within add-ons (for example, having emails for a support system come from support@domain.com instead of the default address).

I ended up applying the following change to debug the issue we were having:

Diff:
diff --git a/src/XF/Mail/Mailer.php b/src/XF/Mail/Mailer.php
index 0b0223c06..0e48d1126 100644
--- a/src/XF/Mail/Mailer.php
+++ b/src/XF/Mail/Mailer.php
@@ -275,6 +275,7 @@ class Mailer
    {
        $to = $message->getTo();
        $toEmails = $to ? implode(', ', array_keys($to)) : '[unknown]';
+       $fromEmail = $message->getFrom();
 
        if (!$transport)
        {
@@ -294,7 +295,7 @@ class Mailer
                    $this->queue->queueForRetry($message, $queueEntry);
                }
 
-               \XF::logException($e, false, "Email to {$toEmails} failed:");
+               \XF::logException($e, false, "Email to {$toEmails} failed from {$fromEmail}:");
                return 0;
            }
        }
@@ -316,7 +317,7 @@ class Mailer
                $this->queue->queueForRetry($message, $queueEntry);
            }
 
-           \XF::logException($e, false, "Email to {$toEmails} failed:");
+           \XF::logException($e, false, "Email to {$toEmails} failed from {$fromEmail}:");
 
            // Any error may put us in an inconsistent state, so we need to reset the connection.
            // Ideally this shouldn't throw anything but it could happen so we just want to swallow
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.9).

Change log:
When logging a failed email exception, include the from email in the exception message
There may be a delay before changes are rolled out to the XenForo Community.
 
Top Bottom