%Mailman.deliver/2 eats my attachments
I want forward emails by simply changing the :to address.
The way it goes:
- Get email by gen_smtp.
- Parse email with
Mailman.Email.parse!/1into%Mailman.Email{} - Change the
:toaddressemail = %Mailman.Email{}; email = Map.put(email, :to, ["[email protected]"]) - Send email by
{:ok, sent_email} = Mailman.deliver(email, config())
After step 3 the email looks like this:
%Mailman.Email{
attachments: [
%Mailman.Attachment{
data: <<0, 0, 0, 0, 0, 171, 205, 239, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 9,
0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
2, 0, ...>>,
disposition: "",
file_name: "users.dets",
mime_sub_type: "octet-stream",
mime_type: "application"
}
],
bcc: [],
cc: [],
data: %{},
delivery: "Wed, 28 Apr 2021 06:45:38 +0200",
from: "[email protected]",
html: "<!DOCTYPE html><html><head><title></title><style type=\"text/css\">p.MsoNormal,p.MsoNoSpacing{margin:0}\r\np.MsoNormal,p.MsoNoSpacing{margin:0}\r\np.MsoNormal,p.MsoNoSpacing{margin:0}\r\np.MsoNormal,p.MsoNoSpacing{margin:0}\r\np.MsoNormal,p.MsoNoSpacing{margin:0}\r\np.MsoNormal,p.MsoNoSpacing{margin:0}\r\np.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div style=\"font-family:menlo, consolas, monospace;color:rgb(0, 0, 128);\">Hallo Welt,<br></div><div style=\"font-family:menlo, consolas, monospace;color:rgb(0, 0, 128);\"><br></div><div style=\"font-family:menlo, consolas, monospace;color:rgb(0, 0, 128);\">ich bin eine HTML Mail. <br></div><div style=\"font-family:menlo, consolas, monospace;color:rgb(0, 0, 128);\"><br></div><div style=\"font-family:menlo, consolas, monospace;color:rgb(0, 0, 128);\">Foo<br></div><div style=\"font-family:menlo, consolas, monospace;color:rgb(0, 0, 128);\">Bar<br></div><div style=\"font-family:menlo, consolas, monospace;color:rgb(0, 0, 128);\">Baz<br></div></body></html>",
reply_to: "",
subject: "Testmail mit Umlauten Ä Ö Ü",
text: "Hallo Welt,\r\n\r\nich bin eine HTML Mail. \r\n\r\nFoo\r\nBar\r\nBaz",
to: ["[email protected]"]
}
When I parse sent_email after step 4 it looks like this:
%Mailman.Email{
attachments: [],
bcc: [],
cc: [],
data: %{},
delivery: "Wed, 28 Apr 2021 06:46:34 +0200",
from: "[email protected]",
html: "<!DOCTYPE html><html><head><title></title><style type=\"text/css\">p.MsoNormal,p.MsoNoSpacing{margin:0}\r\np.MsoNormal,p.MsoNoSpacing{margin:0}\r\np.MsoNormal,p.MsoNoSpacing{margin:0}\r\np.MsoNormal,p.MsoNoSpacing{margin:0}\r\np.MsoNormal,p.MsoNoSpacing{margin:0}\r\np.MsoNormal,p.MsoNoSpacing{margin:0}\r\np.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div style=\"font-family:menlo, consolas, monospace;color:rgb(0, 0, 128);\">Hallo Welt,<br></div><div style=\"font-family:menlo, consolas, monospace;color:rgb(0, 0, 128);\"><br></div><div style=\"font-family:menlo, consolas, monospace;color:rgb(0, 0, 128);\">ich bin eine HTML Mail. <br></div><div style=\"font-family:menlo, consolas, monospace;color:rgb(0, 0, 128);\"><br></div><div style=\"font-family:menlo, consolas, monospace;color:rgb(0, 0, 128);\">Foo<br></div><div style=\"font-family:menlo, consolas, monospace;color:rgb(0, 0, 128);\">Bar<br></div><div style=\"font-family:menlo, consolas, monospace;color:rgb(0, 0, 128);\">Baz<br></div></body></html>",
reply_to: "",
subject: "Testmail mit Umlauten Ä Ö Ü",
text: "Hallo Welt,\r\n\r\nich bin eine HTML Mail. \r\n\r\nFoo\r\nBar\r\nBaz",
to: ["[email protected]"]
}
While sending, the attachments disapear and they do not arrive at the destination mailbox. Please can you show me, what is my mistake here? Do I have to set any special config parameters?
Hey, thanks for the bug report. You're not doing anything wrong; I suppose this has simply never been tried by anyone before. Sorry!
My guess (I haven't checked this though) is that this function doesn't add a disposition (which, as you can see in your example, the disposition field is left blank). This then leads this line to ignore the attachment, instead of including it in the outgoing message.
I can put this on my todo list, but no promises that I'll get to it soon. However, please feel free to create a PR yourself!
Thank you for your immediate response!
I've set the disposition values by hand and it worked fine. I am going to create a PR.
Thank you, looking forward to it!