Sending email attachments doesn't appear to be implemented yet in Meteor's official email package. I've tried the nodemailer suggestion (seen here) but received the error "Cannot read property 'createTransport' of undefined".
I'm attempting to create a CSV file in a data URI and then send that attachment. Here's a snippet of my code when using the official email package:
csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv);
var options = {
from: "xxx@gmail.com",
to: "xxx@gmail.com",
subject: "xxx",
html: html,
attachment: {
fileName: fileName,
path: csvData
}
};
Meteor.call('sendEmail', options);
EDIT:
Here is basically what my nodemailer code looked like:
var nodemailer = Nodemailer;
var transporter = nodemailer.createTransport();
transporter.sendMail({
from: 'sender@address',
to: 'receiver@address',
subject: 'hello',
text: 'hello world!',
attachments: [
{
path: csvData
}
]
});
Not enough rep to comment.
I ended up solving the attachment issue by using Sendgrids NPM package.
If you don't have npm in you meteor app you can read this. https://meteorhacks.com/complete-npm-integration-for-meteor
In your packages.json
Then in a file that runs on the server:
Here is a sample meteor method that gets the url of an attachment (we're using S3) from an attachment collection. This particular method can send any number of attachments to any number of recipients. There is some context specific logic in here but it should be enough to get you up and running sending attachments.
The important part:
A complete method example: