flimflam57
flimflam57

Reputation: 1334

how to add attachments in email package in Meteor

It looks like the email package in Meteor now allows adding attachments similar to how MailComposer does. On my server I have:

Meteor.startup( function() {
process.env.MAIL_URL = "smtp://<my maligun info here>";
});

Meteor.methods({
  sendEmail: function (to, from, subject, text, attachment) {
  // 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,
    text: text,
    attachment: attachment
  });

  }
});

Inside the app I'll have a helper like:

 Template.donateEmail.events({
   'click #send-donate-email': function() {
    var attachment = {
    fileName: "Demographics3.numbers",
    filePath: "/Users/Opal/Desktop/Demographics3.numbers"
  };
    var emailCompose = document.getElementById('compose-donate-email').value;
    var emailSubject = document.getElementById('subject-donate-email').value;
    Meteor.call('sendEmail',
    "[email protected]",     //Session.get('keyDonateEmailSendList'),
    '[email protected]',
    emailSubject,
    emailCompose,
    attachment)
   }
 });

I can get emails to send, but sending but there's no attachments. And the documentation is confusing. Anyone have any more info on this? I'm missing something somewhere.

Upvotes: 1

Views: 686

Answers (1)

flimflam57
flimflam57

Reputation: 1334

Problem solved. Two mistakes in my code. In the Email.send method, it needs to read

"attachments: <some name>" not "attachment: <some name>". 

The second issue is the making sure one specifies the correct absolute path, which in my case on a Mac would be:

"Volumes/Macintosh\ HD/Users/Opal/Desktop/<filename>"

I have found that Apple .numbers files aren't openable, but they will attach. Other files should be OK.

Upvotes: 1

Related Questions