- 
        Couldn't load subscription status. 
- Fork 239
Open
Labels
Description
Describe the bug
When sending an email with Swoosh.Adapters.SMTP, if the email address contains invalid characters, for example [], the adapter crashes with MatchError, rather than reporting an error tuple.
The match error is produced here:
https://github.com/gen-smtp/gen_smtp/blob/685fc92893297d8d726cae1029b9568ae79a0ead/src/mimemail.erl#L999
So maybe this is an issue with gen_smtp, or maybe :mimemail.encode expects valid data, so the adapter should call :smtp_util.parse_rfc5322_addresses on the addresses itself before encoding?
Steps to Reproduce the Bug or Issue
Working:
iex> email = Swoosh.Email.new() |> Swoosh.Email.from("[email protected]") |> Swoosh.Email.text_body("text body") |> Swoosh.Email.to("[email protected]")
iex> Swoosh.Adapters.SMTP.Helpers.body(email, [])
"Content-Type: text/plain;\r\n\t charset=\"utf-8\"\r\nFrom: [email protected]\r\nTo: [email protected]\r\nSubject: \r\nMIME-Version: 1.0\r\nDate: Fri, 7 Apr 2023 11:45:26 +0000\r\nMessage-ID: <fc0cf5f012037f29f3d111b7dc034fea@58ab8ec4cf1d>\r\n\r\ntext body"
iex> Swoosh.Adapters.SMTP.deliver(email, [])
{:error, :no_relay}Broken:
iex> email = Swoosh.Email.new() |> Swoosh.Email.from("[email protected]") |> Swoosh.Email.text_body("text body") |> Swoosh.Email.to("[foo]@bar.com")
iex> Swoosh.Adapters.SMTP.Helpers.body(email, [])
** (MatchError) no match of right hand side value: {:error, {1, :smtp_rfc5322_parse, ['syntax error before: ', ['"[foo]"']]}}
iex> Swoosh.Adapters.SMTP.deliver(email, [])
** (MatchError) no match of right hand side value: {:error, {1, :smtp_rfc5322_parse, ['syntax error before: ', ['"[foo]"']]}}Expected behavior
An {:error, _} tuple is returned according to the @spec of deliver/2, rather than a MatchError.