{"action":"created","issue":{"url":"https://api.github.com/repos/keystonejs/keystone/issues/4487","repository_url":"https://api.github.com/repos/keystonejs/keystone","labels_url":"https://api.github.com/repos/keystonejs/keystone/issues/4487/labels{/name}","comments_url":"https://api.github.com/repos/keystonejs/keystone/issues/4487/comments","events_url":"https://api.github.com/repos/keystonejs/keystone/issues/4487/events","html_url":"https://github.com/keystonejs/keystone/issues/4487","id":269416999,"node_id":"MDU6SXNzdWUyNjk0MTY5OTk=","number":4487,"title":"Wrapper around Mailgun not send attachments","user":{"login":"n-lavrenko","id":7901225,"node_id":"MDQ6VXNlcjc5MDEyMjU=","avatar_url":"https://avatars2.githubusercontent.com/u/7901225?v=4","gravatar_id":"","url":"https://api.github.com/users/n-lavrenko","html_url":"https://github.com/n-lavrenko","followers_url":"https://api.github.com/users/n-lavrenko/followers","following_url":"https://api.github.com/users/n-lavrenko/following{/other_user}","gists_url":"https://api.github.com/users/n-lavrenko/gists{/gist_id}","starred_url":"https://api.github.com/users/n-lavrenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/n-lavrenko/subscriptions","organizations_url":"https://api.github.com/users/n-lavrenko/orgs","repos_url":"https://api.github.com/users/n-lavrenko/repos","events_url":"https://api.github.com/users/n-lavrenko/events{/privacy}","received_events_url":"https://api.github.com/users/n-lavrenko/received_events","type":"User","site_admin":false},"labels":[{"id":566292698,"node_id":"MDU6TGFiZWw1NjYyOTI2OTg=","url":"https://api.github.com/repos/keystonejs/keystone/labels/question","name":"question","color":"fef2c0","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-10-29T17:18:36Z","updated_at":"2018-06-13T13:18:08Z","closed_at":null,"author_association":"NONE","body":"Hi there. \r\nI can't send an attachment file via MailGun. \r\nFirst of all: we don't have any documentation about attachments except on the MailGun site (but there is explaining about using module `mailgun-js`.\r\n\r\nDetails: \r\n\r\n1. I get a file into my `req.files.file` and have a path to the file (so it's a absolute path to the temp folder on my MacOS).\r\n2. Then I create an email instance from keystone class `Email`:\r\n\r\n```\r\nlet email = new keystone.Email({\r\n\ttemplateName: 'request-notification',\r\n\ttransport: 'mailgun'\r\n});\r\n```\r\n\r\n3. And then I send an email with options:\r\n```\r\nlet options = {\r\n\tto: 'email@email.com',\r\n\tfrom: {\r\n\t\tname: 'Nikitos',\r\n\t\temail: 'nikitos@email.com',\r\n\t},\r\n\tsubject: 'Some subject',\r\n\tsomeDataForTemplate: data,\r\n\tbrand: 'Some brand',\r\n        attachment = file.path //   /var/folders/vj/947kggz13hq4gkx7sq_76xjc0000gn/T/7bda0904f4b5caddc78467bdb127a120.png\r\n};\r\n\r\nemail.send(options, callback);\r\n```\r\n4. After `emal.send` I have an error:\r\n\r\n```\r\nMongoose model 'error' event fired on 'User' with error:\r\n source.on is not a function TypeError: source.on is not a function\r\n    at Function.DelayedStream.create (/projects/metallita/node_modules/delayed-stream/lib/delayed_stream.js:33:10)\r\n    at FormData.CombinedStream.append (/projects/metallita/node_modules/combined-stream/lib/combined_stream.js:43:37)\r\n    at FormData.append (/projects/metallita/node_modules/keystone-email/node_modules/form-data/lib/form_data.js:68:3)\r\n    at Request.prepareFormData (/projects/metallita/node_modules/keystone-email/node_modules/mailgun-js/lib/request.js:186:21)\r\n    at Request.request (/projects/metallita/node_modules/keystone-email/node_modules/mailgun-js/lib/request.js:61:12)\r\n    at Mailgun.request (/projects/metallita/node_modules/keystone-email/node_modules/mailgun-js/lib/mailgun.js:74:14)\r\n    at constructor.(anonymous function) [as send] (/projects/metallita/node_modules/keystone-email/node_modules/mailgun-js/lib/build.js:101:24)\r\n    at send (/projects/metallita/node_modules/keystone-email/lib/transports/mailgun/index.js:26:20)\r\n    at /projects/metallita/node_modules/keystone-email/lib/Email.js:125:3\r\n    at /projects/metallita/node_modules/keystone-email/lib/Email.js:77:3\r\n    at Object.exports.renderFile (/projects/metallita/node_modules/pug/lib/index.js:412:12)\r\n    at Email.exports.__express [as engine] (/projects/metallita/node_modules/pug/lib/index.js:455:11)\r\n    at Email.render (/projects/metallita/node_modules/keystone-email/lib/Email.js:75:7)\r\n    at Email.send (/projects/metallita/node_modules/keystone-email/lib/Email.js:123:7)\r\n    at Email.email.send (/projects/metallita/node_modules/keystone/lib/email.js:102:8)\r\n    at /projects/metallita/api/request.js:85:10\r\n(anonymous) @ register.js:83\r\nemitOne @ events.js:115\r\nemit @ events.js:210\r\n(anonymous) @ query.js:2333\r\nrunCallback @ timers.js:781\r\ntryOnImmediate @ timers.js:743\r\nprocessImmediate @ timers.js:714\r\n```\r\n\r\n5. I was tried different option object structures, tried to send the whole file, and via `mailgun.Attachment` constructor:\r\n`var attch = new mailgun.Attachment({data: file, filename: filename});`\r\n**So, nothing works.** \r\n\r\nP.S. I found a solution in using directly `mailgun-js`. This is works fine:\r\n\r\n```\r\nlet mailgun = require('mailgun-js')({\r\n\tapiKey: process.env.MAILGUN_API_KEY, \r\n\tdomain: process.env.MAILGUN_DOMAIN\r\n});\r\n \r\nvar data = {\r\n  from: 'Excited User <me@samples.mailgun.org>',\r\n  to: 'info@info.com',\r\n  subject: 'Hello',\r\n  text: 'Testing some Mailgun awesomness!',\r\n  attachment: file.path\r\n};\r\n \r\nmailgun.messages().send(data, function (error, body) {\r\n  console.log(body); // success\r\n});\r\n```\r\n\r\nBut it is so sad that keystone Email wrapper didn't work with attachments. I think that it is a critical bug. I spent about 4 hours for solve the problem...\r\n\r\nHowever I still enjoy in keystonejs and trust that it will be evolve further!\r\nThank you!"},"comment":{"url":"https://api.github.com/repos/keystonejs/keystone/issues/comments/396933661","html_url":"https://github.com/keystonejs/keystone/issues/4487#issuecomment-396933661","issue_url":"https://api.github.com/repos/keystonejs/keystone/issues/4487","id":396933661,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NjkzMzY2MQ==","user":{"login":"ahhmarr","id":3134813,"node_id":"MDQ6VXNlcjMxMzQ4MTM=","avatar_url":"https://avatars1.githubusercontent.com/u/3134813?v=4","gravatar_id":"","url":"https://api.github.com/users/ahhmarr","html_url":"https://github.com/ahhmarr","followers_url":"https://api.github.com/users/ahhmarr/followers","following_url":"https://api.github.com/users/ahhmarr/following{/other_user}","gists_url":"https://api.github.com/users/ahhmarr/gists{/gist_id}","starred_url":"https://api.github.com/users/ahhmarr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahhmarr/subscriptions","organizations_url":"https://api.github.com/users/ahhmarr/orgs","repos_url":"https://api.github.com/users/ahhmarr/repos","events_url":"https://api.github.com/users/ahhmarr/events{/privacy}","received_events_url":"https://api.github.com/users/ahhmarr/received_events","type":"User","site_admin":false},"created_at":"2018-06-13T13:18:08Z","updated_at":"2018-06-13T13:18:08Z","author_association":"NONE","body":"I just checked it's working \r\n\r\nkeystone-email : 1.0.5\r\nwhich uses mailgun-js : 0.7.15\r\nthis is my code\r\n```new mailer('templates/emails/invoice.pug', {\r\n\t\ttransport: 'mailgun',\r\n\t\tengine   : 'pug',\r\n\t}).send(\r\n\t\t{ invoiceNumber: inv.invoiceNumber, orderNumber: this.ordernumber },\r\n\t\t{\r\n\t\t\tto        : 'myemai',\r\n\t\t\tfrom      : 'fromemail',\r\n\t\t\tapiKey    : process.env.MAILGUN_API_KEY,\r\n\t\t\tdomain    : process.env.MAILGUN_DOMAIN,\r\n\t\t\tattachment: __dirname + `/../${pdf}`,\r\n\t\t},\r\n\t\t(err, resp) => {\r\n\t\t\tconsole.log(err, resp);\r\n\t\t}\r\n\t);```"}}
{"actor":{"display_login":"ahhmarr"}}