New attachments feature in email package

You could also consider handling that processing yourself.
In most of my own usages I tend to build the attachments array and objects programmatically, starting with something like: attachments = [];
I then can iterate through some list/collection/etc of the documents to be attached and for each: [code]
attObject = {};

//code to get/process the fileName and path and set them to variables
// so you could add code for if file name ends with .numbers or other extension to add a contentType string

attObject.fileName = fNameVar;
attObject.filePath = fPathVar;

//if you’ve detected the need to set content type
attObject.contentType = contentVar;

//Push the created attachment object into the attachments array
attachments.push(attObject); [/code]

Then in your Email.send, just use attachments:attachments and all attachment objects in the attachments array will be attached.
I generally find it better to handle that sort of processing myself, rather than leaving it up to users to select the correct options.

Makes sense. Come to think of it, how could you get the full path of the file from the browser? It looks like browsers don’t allow getting a full path from an input text field, which is where the user is putting the files he/she chooses to attach.

That might be a separate issue entirely. I’d guess that you’ll need to handle the file upload separately from the email attachment. Basically you might have to upload the user selected file, store it to a known location server-side, and use that location as the filePath for attaching. Whether you can get the full path on the client machine or not, I don’t think web browsers are allowed direct access to the client filesystem.

There are various packages and methods available for handling file uploads though, so maybe one of those would handle most of the ‘heavy lifting’ and store the file and give quick access to a filePath that would work.

probably it would be nice if the documentation of meteor would be updated with a more detailed version :slight_smile:

I think I’m leaning in the direction of bailing out on the email attachment idea. It perhaps is a little old-school to attach files to emails. Instead, have the client put the file into a cloud service like Dropbox and just link the file in the email. This bypasses the problems with file size limits and issues with file corruption that sometimes happen with attachments.

1 Like