mailman
mailman copied to clipboard
Attachments with extension not in @mime_types fail
Attaching a .docx, for instance, generates the following:
** (ArgumentError) argument error
(stdlib) binary.erl:244: :binary.split/3
lib/mailman/attachment.ex:698: Mailman.Attachment.mime_type_for_path/1
lib/mailman/attachment.ex:668: Mailman.Attachment.inline/1
lib/mailman/attachment.ex:679: Mailman.Attachment.inline!/1
(mothership) lib/mothership.ex:52: Mothership.attach_files/1
(mothership) lib/mothership.ex:43: Mothership.generate_email/1
(elixir) lib/enum.ex:1047: anonymous fn/3 in Enum.map/2
(elixir) lib/enum.ex:1401: anonymous fn/3 in Enum.reduce/3
I have to add mime type in my case.
I had en error with docx documents, I got unknown file. Anybody has fixed this?
Manually adding this to @mime_types in attachments.ex will get you there.
{ ".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" },
Ultimately, I'd think that mime_type_for_path(path) and mime_sub_type_for_path(path) should handle path being nil and default to application/octet
We should do something like mailgun
file_parts = Enum.map(files, fn {field_name, file_name, file_content} ->
[:lists.concat(['--', boundary]),
:lists.concat(['Content-Disposition: format-data; name=\"', :erlang.atom_to_list(field_name), '\"; filename=\"', file_name, '\"']),
:lists.concat(['Content-Type: ', 'application/octet-stream']),
'',
file_content]
end)
Where there is not mime type, just application-octet-stream like you said
This should now be possible without having to hack attachments.ex
– you can specify the mime type/subtype tuple directly via the attach
/inline
functions now.
@MisterToolbox, @Gidrek I know it's been over a year and a half, but if you're still using this it'd be great if you could give this a try and report back if it works for you.