New attachments feature in email package

According to the latest This Week in Meteor newsletter a pull request from tomarcafe was merged into Meteor that makes it possible to send attachments.

This is exactly what I am needing at the moment but it’s not working for me even after a meteor update. I’m using the Windows build.

Anyone know when it will be available?

1 Like

Any update on this feature?

hello guys, how can i make this work? i created a meteor method on the server to send emaIl… and tried to call it through the console…using this

Meteor.call(‘sendEmail’,
‘ianluigilastra@yahoo.com’,
‘test@test.com’,
‘Newsletter 2015’,
$(‘body’).html(), {attachments: [{filename:‘VMN_MS0002_1103.gif’,path:‘http://localhost:1964/upload/images/VMN_MS0002_1103.gif’}]}, function(e,r){if(e){console.log(e.error)}else{console.log(‘message sent’)}});

apparently it wont attach the file?? anybody here care to share how to use the email package? thanks

Email.send only works on the server, so you’ll need to show us your server method.

hello @robfallows here is my server method… hope you can help me thanks

sendEmail: function (to, from, subject, html, attachments) {
check([to, from, subject, html], [String]);

// Let other method calls from the same client start running,
// without waiting for the email sending to complete.
		this.unblock();

	    Email.send({
	      to: to,
	      from: from,
	      subject: subject,
	      html: html,
	      attachments : attachments
	    });
 }

here is my server method… my recent post was being hidden :frowning:

sendEmail: function (to, from, subject, html, attachments) {
check([to, from, subject, html], [String]);

// Let other method calls from the same client start running,
// without waiting for the email sending to complete.
		this.unblock();
      Email.send({
        to: to,
        from: from,
        subject: subject,
        html: html,
        attachments : attachments
      });

}

in the mailcomposer documentation it says

attachments = [{

       filename : 'text1.txt',
       content: "hello world"

}]

but it does not work…

what worked is

attachments = [{

       **fileName** : 'text1.txt',
       content**s**: "hello world"

}]

only attaching text file is the closest thing i ever did as far as attaching files in email is concern please help… :frowning: :((

anybody?? please… i have no answer to this as of now… it can only attach text file other than that nothing… i need to implement inline embedded images…

since nobody replied i manage to solve my problem…

there was no bug on Meteor… the documentation has…

in the Mailcomposer it demonstrated to use { filename: “file.jpg”, Path: “/path/of/file/”}
and i think this is WRONG

when i tried to supply the CORRECT keys it worked. and it was

{ fileName : “file.jpg” , filePath: “/correct/key/is/the/key” }

i hope this helps future email users…

1 Like

hey @codemonkey23 did you manage to make it work?
I see the Email package supports sending of attachments since meteor 1.2 in the same style as mailcomposer.
check this link: https://github.com/andris9/mailcomposer#add-attachments

1 Like

yep. as per my last post i already solved my own problem, the reason for my struggle is that the parameter posted on the manual is ambiguous. so i finally made it work using trial and error

1 Like

Yeah the link to the mailcomposer options is outdated in the meteor documentation.

1 Like

hey, @codemonkey23, I’m trying to get attachments working through Meteor. What do you mean by CORRECT keys? Not sure I follow.

hey matt54 what i mean for keys is the key on a key value pair in an object

e.g {key : value }

{name: “Obi Wan”}
{weapon : “light saber”}

something like this…

so what seems to be the problem in attaching?

warm regards
Ian

Yeah, I was using fileName and filePath as my keys. No luck. The docs say it’s supposed to be an array of objects, but I’m entering something like: { fileName: “Demographics.numbers”, filePath: “Macintosh\ HD/Users/Opal/Desktop/Demographics.numbers” }. I’m stumped.

But are you entering something like:

[{ fileName: "Demographics.numbers", filePath: "Macintosh\ HD/Users/Opal/Desktop/Demographics.numbers" }]

That is: an array of objects?

Is that the actual filePath you are using? Or similar to it? Depending on what problem/error you are having, it may be an issue with the filePath, as a path starting with “Macintosh\ HD” seems unlikely to be found as Macintosh HD is in the Volumes directory, so “/Volumes/Macintosh\ HD/” would be absolute, and a relative path like you have seems unlikely to work unless your Meteor project is in just the right directory.

Otherwise, what everyone is saying should work.
If you have an array of attachment objects with correct name and path, you should be able to attach them.

Email.send({
  to: " ",
  from: " ",
  subject: " ",
  text: " ",
  attachments:[{fileName:" ", filePath:" "}]
}); 

This way you can have multiple attachments simply by adding more objects of format {fileName: " ", filePath: " "}
to the attachments array.

You solved it, soitech. Huge thanks. It turns out I had two problems: The file path, as you pointed out, and I had “attachment” instead of “attachments” listed in the function. One observation its that Apple numbers files, although the WILL attach, they don’t fully attach, as in they can’t be opened. Other files that I’ve tried that succeeded were .png, .xlsx, rtf, txt files. Not sure if this has something to do with the .numbers extension?

It may not know the mime type for .numbers files.
According to the documentation here each attachment object has an optional contentType property, and if not set, the content type will be derived from the fileName. So for fairly standard extensions, it is probably able to get the extension from the file name and set the correct mime-type data, but it probably doesn’t have every possible extension available.

The documentation doesn’t give any info on supported content types, so it would probably require some experimentation to set the contentType yourself. A quick search turned up ‘application/x-iwork-numbers-sffnumbers’ as a possible mime-type for .numbers files. So you might try adding contentType:'application/x-iwork-numbers-sffnumbers' to your attachment object for .numbers files and see if that works, or do a more thorough search to see if you can find the correct mime-type for those files.

Thanks again. Yes, that worked. Mime type for:

  1. Numbers: application/x-iwork-numbers-sffnumbers
  2. Pages: application/x-iwork-pages-sffpages
  3. Keynote: application/x-iwork-keynote-sffkey

I would imagine that the app I’m building would need to provide the user with a selector to confirm a “numbers” attachment, and thus insert the contentType value.