swoosh icon indicating copy to clipboard operation
swoosh copied to clipboard

Error on send email with attachment

Open azharmalik3 opened this issue 1 year ago • 8 comments
trafficstars

Describe the bug

After the update from 1.15.3 to 1.16.3, I am getting errors using the Mailgun adapter when include the email attachments:

(UndefinedFunctionError) function Multipart.Part.file_content_field/5 is undefined or private\\n    (multipart 0.4.0) Multipart.Part.file_content_field(\\\"Evercam Dublin Office I--2024-Mar-28--22:46.jpg\\\", <<255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 2, 0, 0, 1, 0, 1, 0, 0, 255, 254, 0, 16, 76, 97, 118, , 21, 24, ...>>, \\\"attachment\\\", [], [content_type: \\\"image/jpeg\\\"])

Steps to Reproduce the Bug or Issue

Easy to reproduce this error. Just include attachments.

Expected behavior

No response

Your reproducible example

No response

Screenshots or Videos

No response

Platform

  • OTP: 24.0
  • Elixir: 1.14.0

Additional context

We just downgraded swoosh to 1.15.3 it started working again. It means this error especially happened after rewriting multipart in 1.16.1

azharmalik3 avatar Mar 29 '24 10:03 azharmalik3

Now it needs a new dependency, :multipart

princemaple avatar Mar 29 '24 10:03 princemaple

For mailgun.

princemaple avatar Mar 29 '24 10:03 princemaple

I already included :multipart dependency and got the same error.

Is there anything I need to change in my code?

image

I don't see any required changes in the doc.

azharmalik3 avatar Mar 29 '24 10:03 azharmalik3

No change in code needed. Please try removing deps and _build directories.

princemaple avatar Mar 29 '24 10:03 princemaple

Same error

(UndefinedFunctionError) function Multipart.Part.file_content_field/5 is undefined or private

azharmalik3 avatar Mar 29 '24 11:03 azharmalik3

Hmm, I'm currently travelling with very bad internet. I'll have to look into it next week after Easter break. @krainboltgreene would you be interested in having a look?

princemaple avatar Mar 29 '24 11:03 princemaple

We should have a test case for this. I'll look into it today.

krainboltgreene avatar Mar 29 '24 16:03 krainboltgreene

Hi @azharmalik3 , I just manually tested this case |> attachment, with Swoosh.Attachment.new, with {:data, ...} and :inline. It sent without a problem for me. Could you provide a minimal reproduction repo for this issue? Thanks.

princemaple avatar Mar 31 '24 21:03 princemaple

Okay so the function definition is https://hexdocs.pm/multipart/Multipart.Part.html#file_content_field/5 and the call site is https://github.com/swoosh/swoosh/blob/main/lib/swoosh/adapters/mailgun.ex#L195-L203 and the error details:

Multipart.Part.file_content_field(
  \\\"Evercam Dublin Office I--2024-Mar-28--22:46.jpg\\\",
  <<255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 2, 0, 0, 1, 0, 1, 0, 0, 255, 254, 0, 16, 76, 97, 118, , 21, 24, ...>>,
  \\\"attachment\\\",
  [],
  [content_type: \\\"image/jpeg\\\"]
)

So this directly matches the signature of the function both in arguments and type.

The only way this happens is if your complication is incorrect somehow.

krainboltgreene avatar Apr 01 '24 03:04 krainboltgreene

Issue resolved after updating to the latest version.

Thanks all.

azharmalik3 avatar May 17 '24 10:05 azharmalik3