Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachments support is not provided? #3

Open
prasadKodeInCloud opened this issue Sep 2, 2014 · 24 comments
Open

Attachments support is not provided? #3

prasadKodeInCloud opened this issue Sep 2, 2014 · 24 comments

Comments

@prasadKodeInCloud
Copy link

Hi,

Could not send attachments as per the documentation in npm 'mailgun-js' package. https://www.npmjs.org/package/mailgun-js

This feature is not implemented yet?

@marcodejongh
Copy link
Contributor

@prasadKodeInCloud Attachments is not yet implemented.

I think I can implement it for you somewhere this week. If you can not wait feel free to fork this project and implement it yourself and creating a pull request for the changes

@prasadKodeInCloud
Copy link
Author

@marcodejongh Thanks for the reply. Glad if you can implement it in this week.

@marcodejongh
Copy link
Contributor

@prasadKodeInCloud Im not gonna be able to add extra features for a while because its somewhere low on our backlog. But feel free to fork and add the feature yourself

@jerefrer
Copy link

Any news on this ? I'd love to be able to choose the name of the attached file ;)

@marcodejongh
Copy link
Contributor

@jerefrer The send method of this packages is just a simple wrapper around mailgun-js taking care of a lot of oddities in the mailgun api. I've never aspired to wrap the whole of the mailgun-js api that's why I left a non private reference to the internal instance of the mailgun-js instance. This api reference you can use for stuff that isn't wrapped (yet).

So the following should work:

var readFile = Meteor.wrapAsync(Npm.require('fs').readFile)
var path = Npm.require('path');
var filename = 'mailgun_logo.png';
var filepath = path.join(__dirname, filename);

var file = readFile(filepath);

var attch = new MailgunInstance.api.Attachment({data: file, filename: filename});

var data = {
  from: 'Excited User <[email protected]>',
  to: '[email protected]',
  subject: 'Hello',
  text: 'Testing some Mailgun awesomness!',
  attachment: attch
};

mailgunInstance.send(data);

But I do agree it's a decent request and I will definitely add wrapper code handling attachments in the future.

@jerefrer
Copy link

jerefrer commented Jul 7, 2015

Haven't time to try this just now but if Attachment is accessible is should work just fine. That's all I needed thank you :)

If you don't have time to implement it properly maybe you could document this on the README for everyone to see ?

@marcodejongh
Copy link
Contributor

@jerefrer Done, I've also updated the workaround to use a fiber instead of a sync readFile..

Could you tell me if it works when you do try it?

@jerefrer
Copy link

jerefrer commented Jul 7, 2015

I sure will but it won't be before a week or so. Thanks for the doc, doc :)

@shkomg
Copy link

shkomg commented Jul 10, 2015

it'd be great to have it working but it doesn't work like that.

it even just doesn't works when I supply file data as Buffer object to the attachment property.

Any ideas?

Your help is really needed!

Thank you.

@marcodejongh
Copy link
Contributor

@shkomg What is the error you get?

@shkomg
Copy link

shkomg commented Jul 10, 2015

@marcodejongh

I got no error - email is send but with no attachment.

Here is the code (i'm sending the PDF out);

        var toc = new PDFDocument({size: 'A4', margin: 50});
        toc.fontSize(12);
        toc.text('Invoice', 10, 30, {align: 'center', width: 200});
        toc.writeSync(path);

        var readFile = Meteor.wrapAsync(Npm.require('fs').readFile)
        var file = readFile(path);

        Meteor.Mailgun.send({
            to: doc.email,
            from: doc.from,
            subject: 'Invoice for your ad campaign',
            text: message,
            html: Handlebars.templates['contactEmail']({siteURL: Meteor.absoluteUrl(), fromName: doc.name, fromEmail: doc.from, message: message}),
            attachment: file
        });

And when I tried previously proposed solution I can't reach MailgunInstance.api.Attachment

@marcodejongh
Copy link
Contributor

@shkomg With MailgunInstance I meant the pointer to the instance of mailgun.

So it looks like you keep a instance of mailgun on Meteor.Mailgun. So in your case you should use Meteor.Mailgun.api.Attachment.

@shkomg
Copy link

shkomg commented Jul 10, 2015

@marcodejongh

ok, when I do this var attch = new Meteor.Mailgun.Attachment({data: file, filename: "invoice.pdf"});

Meteor throws error:

Exception while invoking method 'getInvoice' TypeError: undefined is not a function

@marcodejongh
Copy link
Contributor

@shkomg You have a getInvoice method somewhere?

@shkomg
Copy link

shkomg commented Jul 10, 2015

@marcodejongh

yes, all this code is in getInvoice method & that error points on this string: var attch = new Meteor.Mailgun.Attachment({data: file, filename: "invoice.pdf"});

It happens so that Meteor.Mailgun is an object and it just doesn't have Attachment method.

I also have tried to use just new Mailgun.Attachment and new Mailgun({api key & domain}).Attachment - all these are objects without Attachment method

@marcodejongh
Copy link
Contributor

@shkomg Try:

var attch = new Meteor.Mailgun.api.Attachment({data: file, filename: "invoice.pdf"});

@shkomg
Copy link

shkomg commented Jul 10, 2015

@marcodejongh

here it is TypeError: Cannot read property 'Attachment' of undefined

@marcodejongh
Copy link
Contributor

@shkomg
This should definitely work:
new Mailgun({api key & domain}).api.Attachment

@shkomg
Copy link

shkomg commented Jul 10, 2015

@marcodejongh it works - it send's email but with no attachment :(

@marcodejongh
Copy link
Contributor

@shkomg Ok I'll add the support the mailgun this weekend that will make it a lot easier

@shkomg
Copy link

shkomg commented Jul 10, 2015

@marcodejongh that'd be awesome!

Thank you!

@shkomg
Copy link

shkomg commented Jul 11, 2015

@marcodejongh Great, that change in readme works! Thank you.

@marcodejongh
Copy link
Contributor

@shkomg Thank you for testing my readme.md ;)

@quape
Copy link

quape commented Jan 7, 2016

I tried to add an attachment with:

'attachment': new mg.api.Attachment({data: Assets.getBinary('logo.png'), filename: 'logo.png'})

wich did not work. The mail was sent but without attachment.

Secondly, if I can make it work, is it possible to mark the attachment as an inline attachment? It's for inline images with are not shown as attachment files in the mail app.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants