XF 2.1 email send failing with mailgun

Mr Lucky

Well-known member
I am using mailgun for SMTP on one forum with no problems, have just set it up on another forum exactly the same as far as I can see and emails are failing.
In Xenforo (private details redacted):

Code:
Server error log
Swift_TransportException: Email to xxx@yyyyyy.com failed: Connection could not be established with host smtp.mailgun.org [Connection refused #111] src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:277
Generated by: xxxxxx Jan 25, 2019 at 9:14 AM
Stack trace
#0 src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php(62): Swift_Transport_StreamBuffer->_establishSocketConnection()
#1 src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(113): Swift_Transport_StreamBuffer->initialize(Array)
#2 src/XF/Mail/Mailer.php(274): Swift_Transport_AbstractSmtpTransport->start()
#3 src/XF/Mail/Mail.php(395): XF\Mail\Mailer->send(Object(Swift_Message), Object(Swift_SmtpTransport), NULL, true)
#4 src/XF/Job/UserEmail.php(72): XF\Mail\Mail->send()
#5 src/XF/Job/AbstractUserCriteriaJob.php(59): XF\Job\UserEmail->executeAction(Object(XF\Entity\User))
#6 src/XF/Job/Manager.php(253): XF\Job\AbstractUserCriteriaJob->run(G)
#7 src/XF/Job/Manager.php(195): XF\Job\Manager->runJobInternal(Array, G)
#8 src/XF/Job/Manager.php(111): XF\Job\Manager->runJobEntry(Array, G)
#9 src/XF/Admin/Controller/Tools.php(120): XF\Job\Manager->runByIds(Array, 8)
#10 src/XF/Mvc/Dispatcher.php(321): XF\Admin\Controller\Tools->actionRunJob(Object(XF\Mvc\ParameterBag))
#11 src/XF/Mvc/Dispatcher.php(248): XF\Mvc\Dispatcher->dispatchClass('XF:Tools', 'RunJob', Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\Tools), NULL)
#12 src/XF/Mvc/Dispatcher.php(100): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\Tools), NULL)
#13 src/XF/Mvc/Dispatcher.php(50): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#14 src/XF/App.php(2177): XF\Mvc\Dispatcher->run()
#15 src/XF.php(390): XF\App->run()
#16 admin.php(13): XF::runApp('XF\\Admin\\App')
#17 {main}
Request state
array(4) {
  ["url"] => string(30) "/xtest/admin.php?tools/run-job"
  ["referrer"] => string(147) "https://mydomain.org.uk/xtest/admin.php?tools/run-job&only_ids=106&_xfRedirect=https%3A%2F%2Fotra.org.uk%2Fxtest%2Fadmin.php%3Fusers%2Femail%26sent%3D2"
  ["_GET"] => array(1) {
    ["tools/run-job"] => string(0) ""
  }
  ["_POST"] => array(3) {
    ["_xfRedirect"] => string(54) "https://mydomain.org.uk/xtest/admin.php?users/email&sent=2"
    ["_xfToken"] => string(8) "********"
    ["only_ids"] => string(3) "106"
  }
}


Mailgun logs tell me this:

nThe mail server could not deliver mail to bounce+37b7a4.0aa2b-pete=xxxx.com@mg.domain.org.uk. The account or domain may not exist, they may be blacklisted, or missing the proper dns entries.\nSender verify failed",

TXT and CNAME entires verified by mailgun (but not MX although they are set up exactly the same as the my other domain which is fine. However I believe MX records are optional?)

The test email is fine when using default sending (php mailer)

Anyone got any ideas, thanks.
 
Last edited:
The XF error you're showing means that the mail never got to Mailgun -- the connection was refused. That generally means that the other side actively closed it. (So the mailgun log entry you quoted would likely be a separate issue.)

In terms of the refusal, if it only happened for one email you sent, then it might really be a temporary issue. If not, then at a guess, it might actually be related to an outgoing firewall. For example, cPanel has the option to block you from connecting to external SMTP servers: https://documentation.cpanel.net/display/68Docs/SMTP+Restrictions
 
Seems to have been the wrong port, mailgun has conflicting documentation: in one place recommends 465, and in another they unrecommend it:

 
Last edited:
Top Bottom