Sending email - how do I include all attachments? Only the first file is being sent.

12 views
Skip to first unread message

Dan Weaver

unread,
Apr 4, 2016, 11:07:04 PM4/4/16
to Webscript.io
I'm sending email as per example at https://www.webscript.io/examples/fileattachment but I can't get the email to include all file attachments included in the form.

When I select multiple files on the form, only the first file is delivered with the email.

My form:

<form action="https://legalnotices.webscript.io/submit" method="post" enctype="multipart/form-data">
 
<input type="text" name="name" />
 
<input type="file" name="attachments" multiple />
 
<input type="submit" value="Submit Notice" />
</form>

My script is the same as on the example page with the small exception that I'm calling the file input field 'attachments' rather than 'attachment'.

How do I get all files included in request.files to be passed as attachments in the email?

Thanks, Dan.

Steve Marx

unread,
Apr 5, 2016, 12:34:27 AM4/5/16
to Dan Weaver, Webscript.io
I just added a feature for this... try using this instead:

attachments = { request.filelists.attachments }

This new field filelists is a dictionary mapping form field names to arrays of file objects (instead of two single file objects). This should handle HTML5's "multiple" file inputs. Let me know if this works for you.


--
You received this message because you are subscribed to the Google Groups "Webscript.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webscriptio...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Weaver

unread,
Apr 5, 2016, 2:44:53 AM4/5/16
to Webscript.io
Wow, that's quick work! Unfortunately, the filelists field isn't working for me. When I try that I get a 500 error and the logs say:

Attachment is missing the required "content" field.

Steve Marx

unread,
Apr 5, 2016, 2:46:08 AM4/5/16
to Dan Weaver, Webscript.io
Oh, sorry, should probably be:

attachments = request.filelists.attachments

(no curly braces around it... it's already a Lua table)

On Mon, Apr 4, 2016 at 11:44 PM, Dan Weaver <danweav...@gmail.com> wrote:
Wow, that's quick work! Unfortunately, the filelists field isn't working for me. When I try that I get a 500 error and the logs say:

Attachment is missing the required "content" field.

Dan Weaver

unread,
Apr 5, 2016, 2:49:43 AM4/5/16
to Webscript.io
Perfect! Works great now. I was just trying a few variants myself but didn't think of removing the curly braces.

Thanks for adding this, it's really helpful. You should add this to the docs too.
Reply all
Reply to author
Forward
0 new messages