Meteor email with Attachment

Hi All,
I use a module in Meteor for sending email with attachments. I Send a test mail on my mailbox and recieve a destroyed attachment with size 1KB. I send img/pdf’s and I allways get same effect. Please help :slight_smile:

Template.dashboard.events({
    'click .sendMail': (e)=>{
        e.preventDefault();
        let mailAdd = $('.mailAddress').val();
        let mailCon = $('.mailContent').val();
        let mailTitle = $('.mailTitle').val();

        Meteor.call('sendEmail',mailAdd, 'xxxxxx@xxxxxxx.pl',mailTitle, mailCon);

    }
})

Meteor.methods({
    sendEmail: function (to, from, subject, text,attachments) {
        check([to, from, subject, text], [String]);
        process.env.MAIL_URL = '###my##hashed###SMTP####';
        this.unblock();

        Email.send({
            to: to,
            from: from,
            subject: subject,
            text: text,
            attachments : attachments = [
                {
                    fileName : "book.pdf" ,
                    filePath: "/home/hexen/Downloads",
                    contents: "this is a test attachment."
                },
            ]
        });

        console.log('Mail wysłany do: ',to);
        console.log('Przesłany przez: ',from);
        console.log('Temat: ',subject);
        console.log('Treść: ',text);
        console.log('Załącznik', attachments);
    }
});

Meteor’s default email package uses mailcomposer behind the scenes. Make sure your attachments array follows the options listed in mailcomposer’s attachment docs. In your example you’re referencing a PDF, so you’ll likely want your attachments array to look something like:

...
attachments: [
  {
    fileName: 'book.pdf',
    filePath: '/home/hexen/Downloads/book.pdf',
  },
]

Note that the filePath should be the full path + filename of the file you want to send.

1 Like

Thx for your Advice! Its working :slight_smile: