Welcome Guest, Not a member yet? Register   Sign In
SMTP fails on localhost
#3

I monitored the network while trying to send mails in case it gives clues about the problem, and I think I figured it out.

Here's a successful mail send from CI3:

Code:
No  Time        Source           Destination        Protocol    Length  Info
----------------------------------------------------------------------------------------------------
14  0.510596    ___.___.___.___  ___.___.___.___    TCP         66      63640 → 587 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 ...
15  0.551575    ___.___.___.___  ___.___.___.___    TCP         66      587 → 63640 [SYN, ACK] Seq=0 Ack=1 Win=8192 Len= ...
16  0.551652    ___.___.___.___  ___.___.___.___    TCP         54      63640 → 587 [ACK] Seq=1 Ack=1 Win=66048 Len=0
21  0.588550    ___.___.___.___  ___.___.___.___    SMTP        145     S: 220 ___.___.___ ESMTP ___ Corporate Mail Serv ...
22  0.589183    ___.___.___.___  ___.___.___.___    SMTP        70      C: EHLO localhost
23  0.628545    ___.___.___.___  ___.___.___.___    SMTP        307     S: 250-___.___.___ Hello localhost [___.___.___. ...
24  0.628808    ___.___.___.___  ___.___.___.___    SMTP        66      C: AUTH LOGIN
27  0.668526    ___.___.___.___  ___.___.___.___    SMTP        72      S: 334 VXNnrh56bWU6
28  0.668638    ___.___.___.___  ___.___.___.___    SMTP        88      C: User: ___
30  0.697355    ___.___.___.___  ___.___.___.___    SMTP        72      S: 334 UGFzcxsf5mQ6
31  0.697514    ___.___.___.___  ___.___.___.___    SMTP        68      C: Pass: ___
33  0.749191    ___.___.___.___  ___.___.___.___    SMTP        91      S: 235 2.0.0 Authentication successful
34  0.749385    ___.___.___.___  ___.___.___.___    SMTP        90      C: MAIL FROM:<___@___.___>
35  0.788907    ___.___.___.___  ___.___.___.___    SMTP        103     S: 250 2.1.0 <___@___.___>... Sender ok
36  0.789059    ___.___.___.___  ___.___.___.___    SMTP        89      C: RCPT TO:<___@___.___>
37  0.828452    ___.___.___.___  ___.___.___.___    SMTP        107     S: 250 2.1.5 <___@___.___>... Recipient ok
38  0.828783    ___.___.___.___  ___.___.___.___    SMTP        60      C: DATA
43  0.857081    ___.___.___.___  ___.___.___.___    SMTP        104     S: 354 Enter mail, end with "." on a line by its ...
44  0.857203    ___.___.___.___  ___.___.___.___    SMTP        506     C: DATA fragment, 452 bytes
47  0.950460    ___.___.___.___  ___.___.___.___    TCP         54      587 → 63640 [ACK] Seq=570 Ack=606 Win=130560 Len ...
48  0.950516    ___.___.___.___  ___.___.___.___    SMTP/IMF    57      from: <___@___.___>, subject: =?UTF-8?Q?Hey?=,
51  0.999937    ___.___.___.___  ___.___.___.___    SMTP        149     S: 250 2.6.0 450 bytes received in 00:00:00; Mes ...
52  1.000092    ___.___.___.___  ___.___.___.___    SMTP        60      C: QUIT
53  1.049809    ___.___.___.___  ___.___.___.___    SMTP        102     S: 221 2.0.0 ___.___.___ closing connection

and the problematic one from the CI4:

Code:
No  Time        Source           Destination        Protocol    Length  Info
----------------------------------------------------------------------------------------------------
87  3.444594    ___.___.___.___  ___.___.___.___    TCP         66      64054 → 587 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 ...
92  3.477140    ___.___.___.___  ___.___.___.___    TCP         66      587 → 64054 [SYN, ACK] Seq=0 Ack=1 Win=8192 Len= ...
93  3.477217    ___.___.___.___  ___.___.___.___    TCP         54      64054 → 587 [ACK] Seq=1 Ack=1 Win=66048 Len=0
94  3.506342    ___.___.___.___  ___.___.___.___    SMTP        145     S: 220 ___.___.___ ESMTP ___ Corporate Mail Serv ...
95  3.506506    ___.___.___.___  ___.___.___.___    SMTP        70      C: EHLO localhost
98  3.535388    ___.___.___.___  ___.___.___.___    SMTP        307     S: 250-___.___.___ Hello localhost [___.___.___. ...
99  3.535588    ___.___.___.___  ___.___.___.___    SMTP        64      C: STARTTLS
101 3.562844    ___.___.___.___  ___.___.___.___    SMTP        84      S: 220 2.0.0 Ready to start TLS
103 3.599593    ___.___.___.___  ___.___.___.___    TLSv1       571     Client Hello
104 3.656124    ___.___.___.___  ___.___.___.___    TLSv1       959     Server Hello, Certificate, Server Hello Done
105 3.656588    ___.___.___.___  ___.___.___.___    TLSv1       61      Alert (Level: Fatal, Description: Unknown CA)
110 3.691253    ___.___.___.___  ___.___.___.___    TCP         54      587 → 64054 [FIN, ACK] Seq=1280 Ack=551 Win=1305 ...
111 3.691470    ___.___.___.___  ___.___.___.___    TCP         54      64054 → 587 [ACK] Seq=551 Ack=1281 Win=64768 Len ...
112 3.698468    ___.___.___.___  ___.___.___.___    SMTP        60      C: QUIT
113 3.702807    ___.___.___.___  ___.___.___.___    TCP         54      64054 → 587 [FIN, ACK] Seq=557 Ack=1281 Win=6476 ...

Notice the difference. CI3 does not start a TLS, but the mail debugger says otherwise.

Upon further investigation, I noticed that in the email class $smtp_crypto is set to "" by default. So the TLS check in _smtp_connect() is never run.

However, in CI4, $SMTPCrypto is set to "tls" by default, so the TLS check is always run unless it's changed.

Now, to solve the problem, all I have to do is set $SMTPCrypto to "". The final state of the code:

PHP Code:
$email = \Config\Services::email();
$config = [
    "protocol"   => "smtp",
    "SMTPHost"   => "___.___.___",
    "SMTPPort"   => 587,
    "SMTPCrypto" => "",             // now it's the same as CI3
    "SMTPUser"   => "___@___.___",
    "SMTPPass"   => "___",
    "newline"    => "\r\n",
];
$email->initialize($config);
$email->setFrom($config["SMTPUser"]);
$email->setTo("___@___.___");
$email->setSubject("Hey");
$email->setMessage("Howdy?");
$email->send(false);
echo 
$email->printDebugger(); 

and voila!

Quote:220 ______.___ ESMTP ___ Corporate Mail Service; Sun, 23 May 2021 16:58:23 +0300

hello: 250-______.___ Hello localhost [___.___.___.___], pleased to meet you.
250-ENHANCEDSTATUSCODES
250-SIZE
250-EXPN
250-ETRN
250-ATRN
250-DSN
250-CHECKPOINT
250-8BITMIME
250-AUTH PLAIN LOGIN DIGEST-MD5 CRAM-MD5 GSSAPI
250-STARTTLS
250 HELP

from: 250 2.1.0 ... Sender ok
to: 250 2.1.5 ... Recipient ok
data: 354 Enter mail, end with "." on a line by itself

250 2.6.0 466 bytes received in 00:00:00; Message id 202105231658233843 accepted for delivery

quit: 221 2.0.0 ______.___ closing connection

Your message has been successfully sent using the following protocol: smtp

Date: Sun, 23 May 2021 08:58:21 -0500
From: <___@___.___>
Return-Path: <___@___.___>
To: ___@___.___
Subject: =?UTF-8?Q?Hey?=
Reply-To: <___@___.___>
User-Agent: CodeIgniter
X-Sender: ___@___.___
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <60aa5f7d96a295.26287360@___.___>
Mime-Version: 1.0


Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Howdy?

While I managed to pinpoint the source of the problem and make it work, I still need a word from the team. Is it safe to set SMTPCrypto to an empty string? If not, that's how the email class works in CI3. Why the change?

If I shouldn't be setting SMTPCrypto to an empty string, how do I solve the problem? Especially on the localhost?

One solution that comes to mind is that modifying SMTPCrypto depending on the environment or something else.
Reply


Messages In This Thread
SMTP fails on localhost - by akinuri - 05-23-2021, 05:28 AM
RE: SMTP fails on localhost - by akinuri - 05-23-2021, 07:56 AM
RE: SMTP fails on localhost - by ogomez - 05-23-2021, 11:26 AM
RE: SMTP fails on localhost - by InsiteFX - 05-23-2021, 11:34 AM
RE: SMTP fails on localhost - by paliz - 05-23-2021, 07:17 PM
RE: SMTP fails on localhost - by InsiteFX - 05-23-2021, 08:35 PM
RE: SMTP fails on localhost - by paliz - 05-23-2021, 09:20 PM
RE: SMTP fails on localhost - by InsiteFX - 05-24-2021, 04:03 AM
RE: SMTP fails on localhost - by akinuri - 05-25-2021, 11:34 AM
RE: SMTP fails on localhost - by chaos - 11-23-2022, 10:50 AM
RE: SMTP fails on localhost - by motoroller - 11-23-2022, 02:26 PM



Theme © iAndrew 2016 - Forum software by © MyBB