kalys / bamboo_ses

AWS SES adapter for Bamboo
MIT License
35 stars 24 forks source link

Cannot send email with headers or attachments and special characters in the name part of the From address #55

Closed michallepicki closed 2 months ago

michallepicki commented 2 months ago

👋🏻 Hi!

I have another issue similar to #54, when sending an email with custom headers or attachments, but also setting the From address to one with special characters (I have included 3 examples but there's probably many more):

    TestHelpers.new_email()
    |> Email.put_header("X-Custom-Header", "header-value")
    |> Email.from({~s(John [Schmidt]), "from@example.com"})
    # |> Email.from({~s(John <3 You), "from@example.com"})
    # |> Email.from({~s(John Schmidt\\), "from@example.com"})
    |> SesAdapter.deliver(%{})

There's an error when building the message content (different errors depending on the example, here's the first one):

 ** (MatchError) no match of right hand side value: {:error, {1, :smtp_rfc5322_parse, [~c"syntax error before: ", [~c"\"[Schmidt]\""]]}}
     code: |> SesAdapter.deliver(%{})
     stacktrace:
       (gen_smtp 1.2.0) /home/michal/bamboo_ses/deps/gen_smtp/src/mimemail.erl:999: :mimemail.encode_header_value/2
       (gen_smtp 1.2.0) /home/michal/bamboo_ses/deps/gen_smtp/src/mimemail.erl:963: :mimemail.encode_headers/1
       (gen_smtp 1.2.0) /home/michal/bamboo_ses/deps/gen_smtp/src/mimemail.erl:210: :mimemail.encode/2
       (bamboo_ses 0.4.4) lib/bamboo/adapters/message/content.ex:87: BambooSes.Message.Content.build_content/7
       (bamboo_ses 0.4.4) lib/bamboo/adapters/message.ex:136: BambooSes.Message.put_content/2
       (bamboo_ses 0.4.4) lib/bamboo/adapters/ses_adapter.ex:51: Bamboo.SesAdapter.deliver/2

I found that there is a helper for preparing and correctly encoding addresses, but in the Raw renderer it is not used (maybe the fix would be to call it there?)