Topic on Extension talk:SwiftMailer

And how to set up SMTP authentication?

18
Атомный трамвай (talkcontribs)

Seems like it couldn't be configured. But how can I use remote mail server?

01tonythomas (talkcontribs)

Extension:SwiftMailer takes in the original SMTP mail server credentials using the $wgSMTP array values given in LocalSettings.php ( Manual:$wgSMTP#Details ) .

Once you have installed the extension, mails will get send by SwiftMailer using these credentials, with an additional option of $wgSMTPAuthenticationMethod = 'tls'; in case you want to enable TLS in SwiftMailer.php ( Extension:SwiftMailer).

Атомный трамвай (talkcontribs)

Thanks for clearing up. But I experience some great troubles using SwiftMailer with configured $wgSMTP. Probably, it's not because of this, while it happened just after these changes. Host just don't do any response. Without specified parameters host works well and it shows it have sent e-mail, while it doesn't, in fact.

Атомный трамвай (talkcontribs)

OK, now everything works. Who knew I must install EXIM (or any MTA) to use feature of mailing? I'm a lunatic. :-)

86.148.157.239 (talkcontribs)

Ok I an experiencing much the same issues as many other have reported namely I have setup the Swiftmailer extension completely in accordance with all the config information.

I have a bog standard Ubuntu build (14.04) and the latest MediaWiki/BlueSpice installation and PHP5 with Apache2

All the $wgSMTP parameters in LocalSettings.php including the require statement and Swiftmailer.php are there as per the extension documentation

I have set up SwiftMailer to do SMTP authentication = "ssl" with $wgSMTP using port 465 (its actually mail.btinternet.com

The only thing that is not 100% clear is IDHost parameter (set to btinternet.com?)

All I get when attempting to send a confirmation email is [bbe3ce2d] 2016-06-16 14:25:11: Fatal exception of type "MWException"

From across the internet I find many similar experiences from other but no clear rationale or solutions, some of them seem to be resolved almost by magic ("it just started working")

Does anyone have a DEFINITIVE solution to this problem?

Regards Colin

01tonythomas (talkcontribs)

Sad to hear that you are experiencing such a problem. To dig more into it, can you enable more debug on fatals by $wgShowExceptionDetails = true; in LocalSettings.php, and paste in the stacktrace (only if its not-sensitive. If it contains sensitive items, please do mail me the same at 01tonythomas[at]gmail[dot]com

86.148.157.239 (talkcontribs)

This is the detail of the error I got back

[468ba65d] /index.php/Special:ConfirmEmail MWException from line 291 of /var/www/npdproject.ddns.net/includes/mail/UserMailer.php: PEAR mail package is not installed

Backtrace:

#0 /var/www/npdproject.ddns.net/includes/User.php(4263): UserMailer::send(MailAddress, MailAddress, string, string, array)

#1 /var/www/npdproject.ddns.net/includes/User.php(4236): User->sendMail(string, string)

#2 /var/www/npdproject.ddns.net/includes/specials/SpecialConfirmemail.php(84): User->sendConfirmationMail()

#3 /var/www/npdproject.ddns.net/includes/specials/SpecialConfirmemail.php(65): EmailConfirmation->showRequestForm()

#4 /var/www/npdproject.ddns.net/includes/specialpage/SpecialPage.php(384): EmailConfirmation->execute(NULL)

#5 /var/www/npdproject.ddns.net/includes/specialpage/SpecialPageFactory.php(553): SpecialPage->run(NULL)

#6 /var/www/npdproject.ddns.net/includes/MediaWiki.php(281): SpecialPageFactory::executePath(Title, RequestContext)

#7 /var/www/npdproject.ddns.net/includes/MediaWiki.php(714): MediaWiki->performRequest()

#8 /var/www/npdproject.ddns.net/includes/MediaWiki.php(508): MediaWiki->main()

#9 /var/www/npdproject.ddns.net/index.php(41): MediaWiki->run()

#10 {main}

Norwin88 (talkcontribs)

I'm having this problem as well. It looks like it's still wanting to use PEAR mail package.

Norwin88 (talkcontribs)

Solved! I had to match the EmergencyContact and PasswordSender values to the email address used in wgSMTP.

Norwin88 (talkcontribs)

I spoke too soon. So emails seem to get sent if it's originating from the address that's set in $wgSMTP, but if for example I try to send a user-to-user email, it fails with the same message. If I configure $wgSMTP for that user's email, then it works again. In essence, it currently is working for a single source email address.

86.148.157.239 (talkcontribs)

You may be right,

Looking at the code ( UserMailer.php in includes/mail I found the section where it checks to see if $wgSMTP is there and if it is checks for PEAR and throws the error above if false. I am assuming that this is where SwiftMailer needs to hook in? but I am a bit of a noob with all this PHP stuff so I am near to the limit of what I understand is happening, although I suspect that it is something to do with getting SwiftMailerHooks.php to intercept at this point posing as the PEAR mailer?

Norwin88 (talkcontribs)

That sounds logical but I'm a total newbie to Mediawiki and Extensions as well. One workaround that seems to work currently is setting $wgNoReplyAddress to the same address, and to set $wgUserEmailUseReplyTo = true.

01tonythomas (talkcontribs)
01tonythomas (talkcontribs)

Okey. I ran the whole process in my local with Gmail smtp server settings, after uninstalling pear-mail from my machine. It seemed to work. Let me paste in some observations I found:

  • It seems to fatal and use PEAR when I chose 'port' => 465 and $wgSMTPAuthenticationMethod = "tls"; According to the docs at https://support.google.com/a/answer/176600?hl=en, on 465, it expects TLS, and setting the global to tls solved my issue.
  • I have $wgUserEmailUseReplyTo = false; and it was correctly sending emails between users ( using Special:EmailUser) and to the same user (via Special:ConfirmEmail).

If you are unsure, please run a $ git pull origin master in your SwiftMailer code and then composer update, followed by the correct SSL or TLS settings in your SwiftMailer.php. If it still fails, please do email me in the above mail address, and we can have maybe a teamviewer session to understand what is going wrong.

Norwin88 (talkcontribs)

Hi Tony, thanks for looking into this so quickly, and thanks for confirming that PEAR Mail is indeed used as a fallback, which is why we see those error messages. Perhaps this bit of information can make it to the Extension page? Several threads here note that very problem. It's quite misleading since we think it's an installation issue when in fact it's a configuration issue.

Anyways, I'll be testing this extension over the next couple of days and will make sure to note any issues here. Thanks again! Hope this extension makes it into core.

86.148.157.239 (talkcontribs)

Hi Tony

Thanks for the insights.

I actually removed and reinstalled the extension (SwiftMailer-REL1_26-07e9cf2)

Followed the set up as per documentation, ran composer update set up for 465 port and ssl

Same result.

I have spent some time trying to unerstand hooks and think I now understand how they work.

I looked at UserMailer and think I understand what is going on, however looking at the script I don't understand how newGood() returns a false value unlike (newFatal ( 'error msg' , $ret)

as per

$ret = Hooks::run( 'AlternateUserMailer', [ $headers, $to, $from, $subject, $body ] );

if ( $ret === false ) {

// the hook implementation will return false to skip regular mail sending

return Status::newGood();

} elseif ( $ret !== true ) {

// the hook implementation will return a string to pass an error message

return Status::newFatal( 'php-mail-error', $ret );}

I am assuming if SwiftMailer returns a false value then UserMailer sets Status to newGood()

If SwiftMailer returns a true value then UserMailer sets Status (newFatal('php-mail-error', $ret)

The SwiftMailer code SwiftMailerHooks puts out wfDebugLog and wfDebug messages as it goes along. It might be useful to check progress of SwiftMailer except not sure where to find them

Is there any simple(dummy level) way to debug SwiftMailer return values?

Colin

86.148.157.239 (talkcontribs)

Yippee Success.

Got the $wfdebug logging working which allowed me to find where the error was being made.

As a long time Windows user it is taking me a long time to get used to case sensitivity especially the regular use of capitalisation in Unix ...............So for example SwiftMailer vrs Swiftmailer vrs swiftmailer which in Windows would often be regarded as the same

MyError was 'Port' not 'port' in $wgSMTP causing SwiftMailerHooks.php to error.

Often the simplest things get overlooked especially in unfamiliar terrority!

All working now message sent

Many thanks to Tony for helping me find my way through this.

Colin

01tonythomas (talkcontribs)

Glad to know. I think there would be some config issue in the above cases too.

Reply to "And how to set up SMTP authentication?"