Fixed SMTP mail not sending using TLS

Status
Not open for further replies.
This would resolve a lot of problems in having to use SMTP with many 3rd party mailers ...

 
Diff:
Subject: [PATCH] Fixed XF 2.3.0 Release Candidate 3 XF-220652 - Do not force SSL connections when using STARTTLS for SMTP
---
Index: src/XF/Mail/Mailer.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/XF/Mail/Mailer.php b/src/XF/Mail/Mailer.php
--- a/src/XF/Mail/Mailer.php    (revision ddc8063dcb669172d80f174602806baabaea28db)
+++ b/src/XF/Mail/Mailer.php    (revision f528d6d31ba7b312c605f572b82edffeb526bf60)
@@ -343,15 +343,14 @@
     {
         switch ($type)
         {
-            case 'smtp';
+            case 'smtp':
                 $factory = new EsmtpTransportFactory();
                 return $factory->create(new Dsn(
-                    !empty($config['smtpEncrypt']) && $config['smtpEncrypt'] != 'none' ? 'smtps' : '',
+                    empty($config['smtpEncrypt']) || $config['smtpEncrypt'] !== 'ssl' ? 'smtp' : 'smtps',
                     $config['smtpHost'],
                     $config['smtpLoginUsername'] ?? null,
                     $config['smtpLoginPassword'] ?? null,
-                    $config['smtpPort'] ?? null,
-                    $config
+                    $config['smtpPort'] ?? null
                 ));
 
             case 'file':
@Chris D can you please share the code modifications for XF 2.2.16?
I'm facing the same issue on that version:
1718207665314.webp
 
The mailer on XF 2.3 and XF 2.2 is different so the fix here only applies to XF 2.3. That version exclusively had a bug in the code but that bug does not exist in XF 2.2.
 
The mailer on XF 2.3 and XF 2.2 is different so the fix here only applies to XF 2.3. That version exclusively had a bug in the code but that bug does not exist in XF 2.2.
I think there is some bug of the same sort (check my latest post, don't pay attention to the title):
 
I don't think this has been fixed.
This is the error I'm getting:
Code:
Symfony\Component\Mailer\Exception\TransportException: Email to from failed: Connection could not be established with host "ssl://email-smtp.eu-west-1.amazonaws.com:587": stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:ssl3_get_record:wrong version number src/vendor/symfony/mailer/Transport/Smtp/Stream/SocketStream.php:154
Generated by: FallenAngel Jun 14, 2024 at 9:01 PM
Stack trace
#0 [internal function]: Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream->Symfony\Component\Mailer\Transport\Smtp\Stream\{closure}(2, 'stream_socket_c...', '/home/vampfreak...', 157)
#1 src/vendor/symfony/mailer/Transport/Smtp/Stream/SocketStream.php(157): stream_socket_client('ssl://email-smt...', 0, '', 60, 4, Resource id #41)
#2 src/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php(251): Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream->initialize()
#3 src/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php(194): Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->start()
#4 src/vendor/symfony/mailer/Transport/AbstractTransport.php(72): Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->doSend(Object(Symfony\Component\Mailer\SentMessage))
#5 src/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php(136): Symfony\Component\Mailer\Transport\AbstractTransport->send(Object(Symfony\Component\Mailer\SentMessage), Object(Symfony\Component\Mailer\DelayedEnvelope))
#6 src/XF/Mail/Mailer.php(308): Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->send(Object(Symfony\Component\Mime\Email))
#7 src/XF/Mail/Mail.php(573): XF\Mail\Mailer->send(Object(Symfony\Component\Mime\Email), Object(Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport))
#8 src/XF/Admin/Controller/ToolsController.php(308): XF\Mail\Mail->send(Object(Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport), false)
#9 src/XF/Mvc/Dispatcher.php(358): XF\Admin\Controller\ToolsController->actionTestEmail(Object(XF\Mvc\ParameterBag))
#10 src/XF/Mvc/Dispatcher.php(265): XF\Mvc\Dispatcher->dispatchClass('XF:Tools', 'TestEmail', Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\ToolsController), NULL)
#11 src/XF/Mvc/Dispatcher.php(121): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\ToolsController), NULL)
#12 src/XF/Mvc/Dispatcher.php(63): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#13 src/XF/App.php(2702): XF\Mvc\Dispatcher->run()
#14 src/XF.php(792): XF\App->run()
#15 admin.php(15): XF::runApp('XF\\Admin\\App')
#16 {main}
Request state
array(4) {
  ["url"] => string(27) "/admin.php?tools/test-email"
  ["referrer"] => string(49) "https://vampfreaks.com/admin.php?tools/test-email"
  ["_GET"] => array(1) {
    ["tools/test-email"] => string(0) ""
  }
  ["_POST"] => array(2) {
    ["_xfToken"] => string(8) "********"
    ["email"] => string(15) "gdgd@live.co.uk"
  }
}
 
Do you have STARTTLS or SSL/TLS selected in your mail options? And are you using port 465?

If your mail server does not support SSL/TLS (not all do) then you'll want to use an alternative port as that one is typically for SSL/TLS only. In that case you'll very likely want to use port 587 with STARTTLS.
 
We have the same problem. Emails stopped being sent when we upgraded to 2.3. We have tried 3 different SMTP providers, (with TLS enabled and disabled), the built-in PHP system, but none of this works.
 
You can open a new thread in the troubleshooting forum with the exact details of the errors you're getting for further support.
 
IMG_6544.webp

The Baby Community Server is hosted by hetzner. Since Hetzner closed emails as a policy, emails were not going. I preferred the corporate mail system. I recommend namecheap as corporate mail. Also, it is a good thing that mail is banned. If there was no ban, I would have to change the IP of the Baby Community site every 6 months. If you run the mail system on your own server, your site will appear as spam after a while.
 
Status
Not open for further replies.
Back
Top Bottom