Page MenuHomePhabricator

Error 5.1.7 (invalid address) when using exchange server as smtp relay
Closed, ResolvedPublic


Author: sephren

Since i upgraded my MediaWiki installation to 1.18, it isn't able to send mails via my smtp relay anymore (MS Exchange Server), for example when creating an user (error message: 501 5.1.7 Invalid address). But it did work with 1.17 and before.

It works again when I change Line 59 of includes/UserMailer.php (second if clause in toString()) in a manner that forces the if clause to be false (included && 1 != 1). Therefore no user name appears in the from header and emails can be send.

I am aware that "wrong" FROM headers are a well-known problem (as seen in bug reports like or and i am sure there is a really huge chance it isn't mediawikis fault. ;-)

Email is configured in LocalSettings.php by $wgSMTP.

Version: 1.18.x
Severity: minor


TitleReferenceAuthorSource BranchDest Branch
Automatically replace outdated quotasrepos/cloud/toolforge/maintain-kubeusers!8taavitaavi/quota-fixmain
maintain-kubeusers: document existing quotasrepos/cloud/toolforge/toolforge-deploy!132taavitaavi/maintain-kubeusers-quotasmain
2023-11-14 releaserepos/phabricator/deployment!26aklapperwork/2023-11-14-releasewmf/stable
Customize query in GitLab

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:59 PM
bzimport added a project: MediaWiki-Email.
bzimport set Reference to bz33087.
bzimport added a subscriber: Unknown Object (MLST).

What is in $wgSMTP?

Could you patch UserMailer.php using r95547 to see if that fixes your problem?

sephren wrote:

I patched UserMailer.php with the follow up revision, but it didn't fix the problem: [SMTP: Invalid response code received from server (code: 501, response: 5.1.7 Invalid address)]

$wgSMTP leads to a SSL tunnel and contains:

$wgSMTP = array(
'host' => "localhost",
'IDHost' => "",
'localhost' => "",
'port' => 15000,
'auth' => false,

Mail Header used to look like this before the upgrade:

Received: from ( by
( with Microsoft SMTP Server id; Thu, 10 Nov 2011
14:10:02 +0100
From: MediaWiki Mail <>

Postfix Server on the same machine which uses the same tunnel/relay:

Received: from ( by
( with Microsoft SMTP Server id; Sat, 1 Oct 2011 23:30:34
From: root <>

Unfortunately i can't tell how mail headers look like now...

I am not sure the solution proposed above is indeed the correct one. Please also check this report on mediawiki discussion page:$wgSMTP&diff=0&oldid=429164

This looks to me like it is the source of this problem. We are using 1.18 behind and SMTP sender authentication verifying University Firewall and when switching to 1.18 all emails were blocked. We found a config: From must be ONLY an email, but not: "name" <>. We were not sure whether this is a mediawiki bug or a problem with our mail infrastructure, so we did not report it, but I now think it is the first.

I confirm that in todays 1.18 SVN the code is still
164: $headers['Return-Path'] = $from->toString();
whereas in 1.19 it is fixed in r99950 but not backported to 1.18 or 1.18wmf1.

Please tag for backporting the trunk to the 1.18 versions.

Sounds like the Return-Path is the cause. The patch was merged in 1.18:

  • $headers['Return-Path'] = $from->toString();

+ $headers['Return-Path'] = $from->address;

The former add the name, the later just the address. I have added a note (r111538à about this bug being fixed for the next 1.18.

It is unlikely we are going to release a 1.18.2 so you will have to add a hack meanwhile.

1.19 will have the patch (release note added with r111539).