[erlang-questions] some help with hackney and multipart

Hynek Vychodil vychodil.hynek@REDACTED
Wed Mar 9 11:55:21 CET 2016


Hi,
Try compare what is sent in body of request made by example with your one
sent by hackney

curl -s --user 'api:YOUR_API_KEY' \
    https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
    -F from='Excited User <YOU@REDACTED>' \
    -F to='foo@REDACTED' \
    -F cc='bar@REDACTED' \
    -F bcc='baz@REDACTED' \
    -F subject='Hello' \
    -F text='Testing some Mailgun awesomness!' \
    --form-string html='<html>HTML version of the body</html>' \
    -F attachment=@files/cartman.jpg \
    -F attachment=@files/cartman.png

Your {multipart, PayloadBase ++ [{file, Attachment}]} doesn't make much
sense to me. Try something like {multipart, [{form, PayloadBase},{file,
Attachment}]} (untested).

Hynek

On Wed, Mar 9, 2016 at 11:31 AM, Caragea Silviu <silviu.cpp@REDACTED>
wrote:

>
>
> Hello,
>
> I'm trying to send an email via mailgun.com using the hackney and I have
> some issues sending attachments (which requires multipart).
>
> https://documentation.mailgun.com/api-sending.html#sending
>
> Basically my interest fields are:
>
>     from
>     to
>     subject
>     text
>     attachment File attachment. You can post multiple attachment values.
> Important: You must use multipart/form-data encoding when sending
> attachments.
>
> I tried the following:
>
> PayloadBase =[
>     {<<"from">>, From},
>     {<<"to">>, To},
>     {<<"subject">>, Subject},
>     {<<"text">>, TextBody},
>     {<<"html">>, HtmlBody}
> ],
>
> Payload = case Attachment of
>     null ->
>         {form, PayloadBase};
>     _->
>         {multipart, PayloadBase ++ [{file, Attachment}]}
> end,
>
> But for some reason the attachment is not sent.. Everything else works as
> expected.
> I don't see how I can set the filed name to "attachment" as required by
> mailgun .. at this this is what I suspect beeing wrong
>
> Silviu
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160309/98f750a6/attachment.htm>


More information about the erlang-questions mailing list