gen-smtp / gen_smtp

The extensible Erlang SMTP client and server library.
Other
684 stars 265 forks source link

(CaseClauseError) no case clause matching: <<0>> #332

Closed puruzio closed 11 months ago

puruzio commented 11 months ago

I am getting the same error mentioned in https://github.com/gen-smtp/gen_smtp/issues/94, but in a different situation. Debugging with io:format("~p~n", [Packet])` in gen_smtp_client.erl displays the following where the 4th item is <<21.3.3.0.2.2.10>>. I'm not sure what that represents.

01:12:05.546 [info] Sent 200 in 13ms

<<"220 Xeams SMTP server;  - Xeams SMTP server; Version: 8.8 - build: 6281; 11/5/23 3:12 AM\r\n">>
<<"250-10.34.72.4. Pleased to meet you\r\n">>
<<"220 Go ahead \r\n">>
<<21,3,3,0,2,2,10>>

FYI. The same program run on another machine doesn't generate this error, and it prints the following output. It appears to me that the network environment or cert authority setting of the first machine is somehow different from this other machine, leading to different outcomes.

<<"220 Xeams SMTP server;  - Xeams SMTP server; Version: 8.8 - build: 6281; 11/5/23 3:14 AM\r\n">>
<<"250-10.34.72.4. Pleased to meet you\r\n">>
<<"220 Go ahead \r\n">>

01:14:36.034 [warning] Description: 'Authenticity is not established by certificate path validation'
     Reason: 'Option {verify, verify_peer} and cacertfile/cacerts is missing'

<<"250-10.34.72.4. Pleased to meet you\r\n">>
<<"250 OK\r\n">>
<<"250 OK\r\n">>
<<"250 OK\r\n">>
<<"354 Start mail input; end with <CRLF>.<CRLF>\r\n">>
<<"250 2.6.0 Queued mail for delivery\r\n">>

Below is the full error message.

01:12:05.563 [error] Task #PID<0.1038.0> started from #PID<0.1030.0> terminating

** (CaseClauseError) no case clause matching: <<0>>
    (gen_smtp 1.2.0) e:/Data/elixir-stuff/fin_reporting_phx16/deps/gen_smtp/src/gen_smtp_client.erl:842: :gen_smtp_client.read_possible_multiline_reply/1
    (gen_smtp 1.2.0) e:/Data/elixir-stuff/fin_reporting_phx16/deps/gen_smtp/src/gen_smtp_client.erl:416: :gen_smtp_client.try_MAIL_FROM/4
    (gen_smtp 1.2.0) e:/Data/elixir-stuff/fin_reporting_phx16/deps/gen_smtp/src/gen_smtp_client.erl:400: :gen_smtp_client.try_sending_it/4
    (gen_smtp 1.2.0) e:/Data/elixir-stuff/fin_reporting_phx16/deps/gen_smtp/src/gen_smtp_client.erl:300: :gen_smtp_client.send_it/2
    (bamboo_smtp 4.2.2) lib/bamboo/adapters/smtp_adapter.ex:87: Bamboo.SMTPAdapter.deliver/2
    (bamboo 2.2.0) lib/bamboo/strategies/task_supervisor_strategy.ex:24: anonymous fn/3 in Bamboo.TaskSupervisorStrategy.deliver_later/3
    (elixir 1.15.5) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2

Function: #Function<0.95237244/0 in Bamboo.TaskSupervisorStrategy.deliver_later/3>

    Args: []
Vagabond commented 11 months ago

I don't see how this badmatch happens, given read_possible_multiline_reply should not be able to return just an untagged binary.

Vagabond commented 11 months ago

ascii code 21 is "negative acknowledge", but I didn't think SMTP used ascii control characters. I think the server doesn't like your TLS handshake, or whatever.

Vagabond commented 11 months ago

Can you try supplying trace_fun to the client options: https://github.com/gen-smtp/gen_smtp/blob/1.2.0/src/gen_smtp_client.erl#L946C30-L946C39

Vagabond commented 11 months ago

I suspect the TLS negotiaton goes wrong here https://github.com/gen-smtp/gen_smtp/blob/1.2.0/src/gen_smtp_client.erl#L777, and the server thinks we're doing TLS and the client doesn't

puruzio commented 11 months ago

Changing to tls: :never fixed the issue. Thank you!

Vagabond commented 11 months ago

It might be helpful if you could capture more information so we could fix the issue properly.

puruzio commented 11 months ago

What's the suggested steps I should follow to do so?

Vagabond commented 11 months ago

You could privately let me try using the server, or you could pass [{trace_fun, fun io:format/2}] to the client options and see what the trace gives you, or add a io:format around https://github.com/gen-smtp/gen_smtp/blob/1.2.0/src/gen_smtp_client.erl#L777

puruzio commented 11 months ago

Else -> io:format("~p~n", [trace(Options, "~p~n", [Else])]), false

printed "ok"

Let me know if that's not what you meant.

Vagabond commented 11 months ago

Weird, that means that ssl:connect() is returning ok, not {ok, Socket}. What OTP version is this?

puruzio commented 11 months ago

OTP 26