Giter Site home page Giter Site logo

mailgun-js-boland's Introduction

mailgun.js

Simple Node.js module for Mailgun.

Maintenance Notice

This library is no longer maintained. Mailgun now has a supported, official library at https://github.com/mailgun/mailgun-js. It is also available as an npm at https://www.npmjs.com/package/mailgun.js. I'd encourage everyone to migrate from this library to the official library. If you have questions or issues with the official library, please raise issues there.

mailgun-js-boland's People

Contributors

aaronosher avatar adammagaluk avatar antoniosou avatar bojand avatar caub avatar chilts avatar codekonami avatar corbinu avatar daltones avatar developedbyme avatar erwanlent avatar grahamj avatar highlycaffeinated avatar jonnyjon avatar kdekooter avatar kopertop avatar lawrence79 avatar lpellegr avatar maxmatthews avatar mhgbrg avatar modelga avatar robertherhold avatar sabakugaara avatar sandinmyjoints avatar siygle avatar sofiapm avatar soplakanets avatar stefanosala avatar suchitagarwal avatar timsvoice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mailgun-js-boland's Issues

`Error: Cannot find module 'mailgun-js'`

In recent versions (at least 0.4+) this module fails to load in my app. Possibly because package.json still specifies main as ./mailgun.js, which no longer exists?

Failed to parse json - unable to do npm install

Hi,

the npm install method is not working - get the following error:

npm WARN package.json [email protected] No README data
npm ERR! Failed to parse json
npm ERR! Unexpected end of input
npm ERR! File: /Users/impresario/.npm/form-data/0.1.4/package/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR! 
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

Thanks,
Jatin

API completeness and forward stability

So this is a list of all API endpoints and methods mentioned in the API docs. I think that this might be helpful for reaching 100 % completeness. Feel free to edit this and check finished methods.

I also nagged @mailgun, about the API schema on twitter. Maybe we should file an issue.

/<domain>/messages
  • POST /<domain>/messages
  • POST /<domain>/messages.mime
  • GET domains/<domain>/messages
  • DELETE domains/<domain>/messages/<message>

Retrieving and deleting stored messages would kick ass.

/domains
  • GET /domains
  • GET /domains/<domain>
  • POST /domains
  • DELETE /domains/<domain>
  • GET /domains/<domain>/credentials
  • POST /domains/<domain>/credentials
  • PUT /domains/<domain>/credentials/<login>
  • DELETE /domains/<domain>/credentials/<login>
/<domain>/unsubscribes
  • GET /<domain>/unsubscribes
  • GET /<domain>/unsubscribes/<address>
  • DELETE /<domain>/unsubscribes/<address or id>
  • POST /<domain>/unsubscribes
/<domain>/complaints
  • GET /<domain>/complaints
  • GET /<domain>/complaints/<address>
  • POST /<domain>/complaints
  • DELETE /<domain>/complaints/<address>

This could be very useful for automated evaluation or notification of support personnel.

/<domain>/bounces
  • GET /<domain>/bounces
  • GET /<domain>/bounces/<address>
  • POST /<domain>/bounces
  • DELETE /<domain>/bounces/<address>
Stats
Events
/routes/
  • GET /routes
  • GET /routes/<id>
  • POST /routes
  • PUT /routes/<id>
  • DELETE /routes/<id>
/<domain>/campaigns
  • GET /<domain>/campaigns
  • GET /<domain>/campaigns/<id>
  • POST /<domain>/campaigns
  • PUT /<domain>/campaigns/<id>
  • DELETE /<domain>/campaigns/<id>
  • GET /<domain>/campaigns/<id>/events
  • GET /<domain>/campaigns/<id>/stats
  • GET /<domain>/campaigns/<id>/clicks
  • GET /<domain>/campaigns/<id>/opens
  • GET /<domain>/campaigns/<id>/unsubscribes
  • GET /<domain>/campaigns/<id>/complaints
/<domain>/webhooks
  • GET /domains/<domain>/webhooks
  • GET /domains/<domain>/webhooks/<webhookname>
  • POST /domains/<domain>/webhooks
  • PUT /domains/<domain>/webhooks/<webhookname>
  • DELETE /domains/<domain>/webhooks/<webhookname>

Webhooks support would be sexy. Maybe I can come around to submitting a PR.

/lists/
  • GET /lists
  • GET /lists/<address>
  • POST /lists
  • PUT /lists/<address>
  • DELETE /lists/<address>
  • GET /lists/<address>/members
  • GET /lists/<address>/members/<member_address>
  • POST /lists/<address>/members
  • PUT /lists/<address>/members/<member_address>
  • POST /lists/<address>/members.json I think this one's buggy.
  • DELETE /lists/<address>/members/<member_address>
/address/
  • GET /address/validate
  • GET /address/parse

Not really neccessary. We could do this on our own, if needed.

[SyntaxError: Unexpected end of input]

I am trying to add users to a mailing list, but I am seeing the error mentioned in the title. Although, to my understanding my code should work as expected. The code looks as follows..

var config = require('../../config/environment');

var api_key = config.mailgun.apiKey;
var domain = config.mailgun.domain;

var Mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});

exports.subscribe = function(req, res) {
  var members = [req.body]
  Mailgun.lists('[email protected]').members().add({
    members: members, 
    subscribed: true
  }, function(err, body) {
    if(err) { return  res.send(err); }
    return res.send(200);
  });
};

The request body is the object {address: [email protected]}

I'm pretty positive it's something that is staring me right in the face, but I can't find the light in all this darkness. Any help would be much appreciated!

Update:

Ok I figured out I needed to be making a GET request and shoving the email into the params. No errors now, but I'm not seeing any users being added to list. Also, the body param in the callback logs out undefined.

Multiple params to mailgun

Hey, i have a question, when, I use:

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

mailgun.messages.send(data, function (error, response, body) {
  console.log(body);
});

The mailgun allows multiple tags, but js not accept.
An array would be cool to send multiple tags or params to get stats.

Like this request with cURL:

curl -s --user 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0' -G \
    https://api.mailgun.net/v2/samples.mailgun.org/stats \
    -d event='sent'\
    -d event='opened' \
    -d skip=1 \
    -d limit=2

npm install issues

When i try to install 0.6.7 I get the following error:

npm WARN unmet dependency /Users/bert/Sites/Kweetet-Diff/API/node_modules/mailgun-js/node_modules/path-proxy requires inflection@'~1.3.0' but will load
npm WARN unmet dependency /Users/bert/Sites/Kweetet-Diff/API/node_modules/mailgun-js/node_modules/inflection,
npm WARN unmet dependency which is version 1.5.3

Error('"name" and "value" are required for setHeader()?

Hi
I get the above error
when i run mailgun.messages().send in the code:
var data = {
from: locals.owner.firstName + " " + locals.owner.lastName + "<" + locals.owner.email + ">",
to: user.email,
subject: locals.process.processName ,
text: locals.process.emailTemplate,
attachment: filepath
};

 mailgun.messages().send(data, function (error, body) {
   console.log(index,error,body);
   if (error) {
     cbFunc(error);
   }
 });

any ideas?

thanks very much!

Reply-To Support

Hi i was not able to find any documentation regarding whether reply to is supported by the module.

I studied the mail gun documentation, and they clearly mention support for a reply to field. Any answer will be helpful.

logs should not dump by console.error

Sometimes the warning log is annoy, could you add an option to close these logs, or pipe them to a readable/writable stream?

For example:

require('mailgun-js')({mute: true}) // don't show logs

referenceError in request.js on line 253

Bugsnag showed me this error with stacktrace, i'm guessing that e has to be err

ReferenceError: e is not defined
node_modules/mailgun-js/lib/request.js:253:30 none
events.js:95:17 EventEmitter.emit
http.js:1548:9 socketErrorListener
events.js:95:17 EventEmitter.emit
tls.js:1432:17 onerror
events.js:117:20 EventEmitter.emit
net.js:441:14 none
node.js:459:13 _tickDomainCallback

Fails on Windows (path.join inserts backslash)

In mailgun.js in line 29

 var fullpath = path.join('/', this.getDomain(resource), resource);

When on Windows you get a path with backslashes .e.g. \mydomain.com\messages.
The use of path is probably bad as it works under the assumption that we are dealing with file system paths.

Instantiate mailgun object within the module

I'm wondering if it would be sensible to use only one instance of the mailgun object and initialize this object when requiring mailgun-js for the first time. Once the module is initialized the user/developer is able to require mailgun-js without providing credentials or creating a new instance.

var Mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});

'stripe-node' (https://github.com/stripe/stripe-node/) for example is used like this:
var stripe = require('stripe')(' your stripe API key ');

Add retry mechanism to retry sending emails due to network failure

I was wondering, if mailgun-js could support no of times to retry as one of the options in mailgun. For example,

var mailgun = require('mailgun-js')({
                      apiKey: api_key, 
                      domain: domain,
                      timeout: 2000,
                      retry: 3 });

Its trivial to implement as a retry callback function. But it ll be lot neater to have this option integrated within mailgun.

Mailgun status callback not firing

Hey, I don't know whether this is something to do with mailgun-js or my misunderstanding of the code, but I'm attempting to try and get the status of the message once it's reached Mailgun, such as if the email bounces back. It seems to be stuck on pending even though I assumed that by checking mailgun.messages('<messageid@domain>').info() I would get whether it had completed successfully or not?

I have a simple example that doesn't seem to return what I was expecting, I was wondering if it was possible to reproduce my problem:

var Mailgun = require('mailgun-js');

var apiKey = 'key-abc123xyz890'
var domain = 'madeupdomain.mailgun.org'

var mailgun = Mailgun({
  apiKey: apiKey,
  domain: domain
});

mailData = {
  from: "[email protected]",
  to: '[email protected]',
  subject: "Test",
  html: 'Test'
}

mailgun.messages().send(mailData,
  function (err, body) {
    if (err)
      return console.log(err);

    setInterval(function () {
      console.log(mailgun.messages(body.id).info());
    }, 1000);

    return console.log(body.id);
  }
);

And this just fires out this indefinitely:

{ state: 'pending' }
{ state: 'pending' }
{ state: 'pending' }
{ state: 'pending' }
{ state: 'pending' }

Any help appreciated, don't know whether it's a bug or me!

Cheers
Matt

Note: I get the same results (constantly pending) with:

mailgun.events().get({
  ascending: 'no',
  limit: 1
});

config important `true` error

when

mailgun.messages().send(config, function (err, data) { 
  // do stuff with arguments 
});

such that config.important exists and is true and config.attachment exists and is string or buffer

yields the following error:
_http_outgoing.js:433 throw new TypeError('first argument must be a string or Buffer'); ^ TypeError: first argument must be a string or Buffer at ClientRequest.OutgoingMessage.write (_http_outgoing.js:433:11)

Very strange behavior, as this error is not thrown when config.attachment does not exist OR when config.important is removed, the attachment remains valid and is delivered as expected.

They do not co-exist well.

URIError: URI malformed

Hi there,

We at @fiftythree are using this module in production for our https://mix.fiftythree.com notification emails. Thanks for the great library! =)

For a while now, we've been seeing an occasional error when calling messages().send():

URIError: URI malformed
    at encodeURIComponent (native)
    at Object.QueryString.escape (querystring.js:117:10)
    at querystring.js:152:33
    at Array.map (native)
    at Object.QueryString.stringify.QueryString.encode (querystring.js:145:29)
    at Request.request (/app/node_modules/mailgun-js/lib/request.js:52:25)
    at [object Object].Mailgun.request (/app/node_modules/mailgun-js/lib/mailgun.js:48:14)
    at [object Object].constructor.(anonymous function) [as send] (/app/node_modules/mailgun-js/lib/build.js:101:24)
    (then our calling code)

That's coming from the native querystring.stringify here:

https://github.com/1lobby/mailgun-js/blob/443296e950d57fcd5622468d1a2585816550e65e/lib/request.js#L54

I know the bug is from the native module, but given that that's an implementation detail of this module, I thought you might like to know.

We've added debug logging to our code, and tried a couple of workarounds, but still haven't been able to squash this. I'll add that info and other notes in a comment.

Thanks!

Add .idea to .npmignore

.idea is in the .gitignore, however since you also have a .npmignore it does not filter those items by default. Therefore I recommend adding .idea also to the .npmignore file as it is included in the current npm package.

Timeout?

Is there a way to set (or add) a timeout on a connection. We are sending millions of emails via MailGun, and occasionally our message pump (which simply drains a redis list with prepared content), hangs in the call to message().send. It just never calls the callback. It's intermittent, we can send 100k emails or millions and then it pops up. My thoughts are that something went wrong the connection and it needs to timeout, or a callback is being missed somewhere in mailgun-js and node goes idle (our status monitor for example keeps running). Any ideas?

Please add ability to send few attachments.

Please add ability to send few attachments. I have found this snippet

var mail = {
                from: alertFrom,
                to: this.recipients,
                subject: fmt('%s API alert (%s)', this.instance.toUpperCase(), new Date()),
                html: this.template,
                attachments: [
                    {
                        filename: `${this.instance}.log`,
                        filePath: path.resolve(`${__dirname}/../logs/${this.instance}.log`)
                    },
                    {
                        filename: `${this.instance2}.log`,
                        filePath: path.resolve(`${__dirname}/../logs/${this.instance2}.log`)
                    }
                ]
            };

with array of attachments, but this does not work.

CC and BCC for MIME types

It seems that it is not possible to have CC and BCC in an email with HTML body, for example, since you have to explicitly set "to" field after mailComposer builds the message:

mailComposer.buildMessage(function(mailBuildError, messageSource) {
    var dataToSend = {
      to: recipients[0],
      message: messageSource
    };

    mgSender.messages().sendMime(dataToSend, function (error, response) {
    ...

Improve API

It would be nice to have instance methods. So we can do something like:

mailgun.lists.get(...)
mailgun.lists.post(...)
mailgun.lists.list(...) // alias for get
mailgun.lists.create(...) // alias for post
mailgun.lists('[email protected]').get(...)
mailgun.lists('[email protected]').put(...)
mailgun.lists('[email protected]').delete(...)
mailgun.lists('[email protected]').update(...) // alias for put
mailgun.lists('[email protected]').members.get(...) // lists members
mailgun.lists('[email protected]').members.list(...) // alias for get
mailgun.lists('[email protected]').members.post(...) // create
mailgun.lists('[email protected]').members.create(...) // alias for post
mailgun.lists('[email protected]').members('[email protected]').get(...) // gets member info
mailgun.lists('[email protected]').members('[email protected]').update(...) 
mailgun.lists('[email protected]').members('[email protected]').update(...) // alias for put
mailgun.lists('[email protected]').members('[email protected]').delete(...)

That's the general idea. would be nicer to work with perhaps. Might be a major change internally. Not sure.

Support for multiple tags?

Mailgun supports up to 3 custom tags using the o:tag param. Don't see this doc'd, and skimming the code, I'm not seeing how this would currently work. Is it supported?

More generally, do you handle other cases where params can be repeated more than once (to, attachment, etc.). Apologies if this has been covered somewhere but I'm not finding it. Thanks!

Request: Support MIME route

Really appreciate this module so far. I use it for all my Mailgun routes except MIME. I tried adding it myself but could not get it to work. My use case is sending calendar invites -- Outlook only recognizes ICS files sent as 'alternative messages' vs attachments, but Mailgun's regular API only supports text/html alternatives. My current solution is to use a separate mailgun node library (https://github.com/shz/node-mailgun), but it also uses the OLD Mailgun api at mailgun.net/api/. I also asked Mailgun if they could add 'calendar' as another format to their API, but seems unlikely.

Is there any work being done to support Mailgun's MIME route that I can help test? For the benefit of others, here's my final working code (caveat emptor: creating the ICS string is another fair challenge!):

var mailgun = require('mailgun'); // node-mailgun
var mailcomposer = require('mailcomposer');

mailcomposer.setMessageOption({
    from: '[email protected]',
    to: [[email protected]],
    body: "Hello world!",
    html: '<strong>Hello world!</strong>',
    subject: 'Well hello there!'
});

/* For Outlook */
mailcomposer.addAlternative({
    contents: ics_string,
    contentType: 'text/calendar'
});

/* Google and everyone else */
mailcomposer.addAttachment({
    contents: ics_string,
    contentType: 'application/ics',
    fileName: 'invite.ics'
});

mailcomposer.buildMessage(function (err, messageSource) {
    var mailer = new mailgun.Mailgun(MAILGUN_API_KEY);
    mailer.sendRaw('[email protected]', ['[email protected]'], messageSource, function (err) {
        console.log(err || 'no error');
        process.exit();
    });
});

Ultimate vision (for 1.0.0?)

Ideally we would have JSON Schema (+ Hypertext?) representation of the API. This could be manually created using existing documentation. There are tools to help with this; still, I think this would be rather time consuming, error prone, and a very manual task. Lot's of checking and testing would might be needed. Ideally Mailgun could provide the schema via an API route (ie. https://pi.mailgun.net/schema) for consumption. Using this it would be fairly easy to create a self-generating / updating library with support for all of the api, and it would catch any future changes and additions. Heroku uses this mechanism for their node client.

http GET parameters are not getting passed in querystring

I noticed when using mailgun.lists.members.list and specifying a limit and offset in the second data parameter the results never seemed to change.

In your code your passing

    var opts = {
      url: url,
      method: method,
      headers: headers,
      form: data
    };

But form would not be valid for GET requests.

When I stringify the data object and add it as a querystring to opts.url everything works as expected.

Expand Attachment to accept more options and streaming

The Attachment object and related code should be expanded to support adding additional info to the attachment object such as length and content type. Also it would be good to support readable stream as the content data, so that we directly stream from other sources. More background on this in PR #36.

Public end points

From looking over the test's, it does not seem like public end points are supported.

I want to be able to do something like this.

mailgun.post("/address/validate", {
  address: '[email protected]'
}, function (error, response) {});

This is the public end point api.mailgun.net/v3/address/validate docs
And this is what my current solution looks like

var url = "https://api:" + this.publicKey + "@api.mailgun.net/v3/address/validate";
request({
  url: url,
  form: {
    address: encodeURI(email)
  }
}, function (error, response, data) {
  if (error) {
    defer.reject(error);
  }
  defer.resolve(data);
});

Differentiate client vs. server errors

Hi there,

Great library! We're using it for mix.fiftythree.com (just launched) and it's serving us very well. Thanks.

The only big thing we're missing is a way to differentiate client vs. server errors. E.g. 'to' parameter is not a valid address vs. socket hangups or ECONNREFUSED (which we're seeing today).

Looking at the code, the problem is that all errors get generalized to one:

    if (!error && res.statusCode !== 200) {
      var msg = body ? body.message || body.response : body || chunks;
      error = new Error(msg);
    }

https://github.com/1lobby/mailgun-js/blob/v060/lib/request.js#L226-L229

One thing to do here could be to add a statusCode property and let the client take care of doing whatever differentiation it wants to do, e.g. using the documentation:

http://documentation.mailgun.com/api-intro.html#errors

Another could be to simply differentiate 4xx vs. 5xx and add a cause ('client' or 'error') property, or something like that. Or throw different ClientError vs. ServerError classes, etc.

Happy to open a PR here, but just wanted to get the conversation started. Thanks!

Request Entity Too Large error

I am making this request:

var filepath = path.join(__dirname, "/output/" + job.jobId + ".zip");

var data = {
    from: 'Name <[email protected]>',
    to: email,
    subject: 'Test',
    text: 'Test',
    attachment: filepath
};

mailgun_client.messages().send(data, function(error, body) {
    if(error) console.log(error)
    console.log(body);
});

and am getting this error:

{ [Error: <html>
<head><title>413 Request Entity Too Large</title></head>
<body bgcolor="white">
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx/1.7.9</center>
</body>
</html>
] statusCode: 413 }

How do I fix this? Is it because the attachment is too big?

Webhook Validation Issue

I'm validating my webhooks exactly as described in the README.

Delivered messages, clicks, and opens are working flawlessly. However, when I receive requests for dropped messages, hard bounces, and spam complaints, I'm getting the following in my console:

[mailgun] Stale Timestamp: this may be an attack
[mailgun] However, this is most likely your fault

[mailgun] run `ntpdate ntp.ubuntu.com` and check your system clock

[mailgun] System Time: Thu Mar 26 2015 17:30:54 GMT-0400 (EDT)
[mailgun] Mailgun Time: Invalid Date undefined
[mailgun] Delta: NaN

I decided to log the body of the request, to see what Mailgun was actually returning, but it turned out to be an empty (logging the body of the request for delivered messages, clicks, and opens shows exactly what one would expect). This is an issue with Mailgun, right? Am I missing something?

Browserify issue with dependency

I'm trying to use mailgun-fs in a browserify environment, and I'm getting this issue:

SyntaxError: Line 4: Unexpected token var while parsing /Users/richard/src/beagle/node_modules/mailgun-js/node_modules/proxy-agent/node_modules/pac-proxy-agent/node_modules/get-uri/node_modules/ftp/lib/connection.js while parsing file: /Users/richard/src/beagle/node_modules/mailgun-js/node_modules/proxy-agent/node_modules/pac-proxy-agent/node_modules/get-uri/node_modules/ftp/lib/connection.js
    at Stream.end (/Users/richard/src/beagle/node_modules/browserify/node_modules/insert-module-globals/index.js:73:21)
    at _end (/Users/richard/src/beagle/node_modules/browserify/node_modules/insert-module-globals/node_modules/through/index.js:65:9)
    at Stream.stream.end (/Users/richard/src/beagle/node_modules/browserify/node_modules/insert-module-globals/node_modules/through/index.js:74:5)
    at Transform.onend (/Users/richard/src/beagle/node_modules/browserify/node_modules/readable-stream/lib/_stream_readable.js:523:10)
    at Transform.g (events.js:199:16)
    at Transform.emit (events.js:129:20)
    at /Users/richard/src/beagle/node_modules/browserify/node_modules/readable-stream/lib/_stream_readable.js:965:16
    at process._tickCallback (node.js:355:11)

Anyone else seen this? mailgun-js v0.6.8

Is Batch Sending supported?

Good day, thank you for the great library!

Is Batch Sending supported?

like curl:

curl -s --user 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0' \
    https://api.mailgun.net/v2/samples.mailgun.org/messages \
    -F from='Excited User <[email protected]>' \
    -F [email protected] \
    -F [email protected] \
    -F recipient-variables='{"[email protected]": {"first":"Bob", "id":1}, "[email protected]": {"first":"Alice", "id": 2}}' \
    -F subject='Hey, %recipient.first%' \
    -F text='If you wish to unsubscribe, click http://mailgun/unsubscribe/%recipient.id%'

win7 + proxy

Hello

When i use mailgun-js with Win7 behind proxy, i have this error

{ [Error: write EPROTO 101057795:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:782:
] code: 'EPROTO', errno: 'EPROTO', syscall: 'write' }

my code

var api_key = 'key-dxxxxxxxxxxxxxxxxxx';
var domain = 'sandboxe8xxxxxxxxxxxxxxxxxx.mailgun.org';
var mailgun = require('mailgun-js')({
    apiKey: api_key,
    domain: domain
    proxy: "https://LOGIN:[email protected]:8080"
});

var data = {
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Hello',
  text: 'hello'
};

mailgun.messages().send(data, function (error, body) {
  console.log(error);
  console.log(body);
});


Thank

Request: Support MIME route

Really appreciate this module so far. I use it for all my Mailgun routes except MIME. I tried adding it myself but could not get it to work. My use case is sending calendar invites -- Outlook only recognizes ICS files sent as 'alternative messages' vs attachments, but Mailgun's regular API only supports text/html alternatives. My current solution is to use a separate mailgun node library (https://github.com/shz/node-mailgun), but it also uses the OLD Mailgun api at mailgun.net/api/. I also asked Mailgun if they could add 'calendar' as another format to their API, but seems unlikely.

Is there any work being done to support Mailgun's MIME route that I can help test? For the benefit of others, here's my final working code (caveat emptor: creating the ICS string is another fair challenge!). For this example, I'd like a 'sendRaw' method to be available in mailgun-js:

var mailgun = require('mailgun'); // node-mailgun
var mailcomposer = require('mailcomposer');

mailcomposer.setMessageOption({
    from: '[email protected]',
    to: [[email protected]],
    body: "Hello world!",
    html: '<strong>Hello world!</strong>',
    subject: 'Well hello there!'
});

/* For Outlook */
mailcomposer.addAlternative({
    contentEncoding: '7bit',
    contents: ics_string,
    contentType: 'text/calendar'
});

/* Google and everyone else */
mailcomposer.addAttachment({
    contents: ics_string,
    contentType: 'application/ics',
    fileName: 'invite.ics'
});

mailcomposer.buildMessage(function (err, messageSource) {
    var mailer = new mailgun.Mailgun(MAILGUN_API_KEY);
    mailer.sendRaw('[email protected]', ['[email protected]'], messageSource, function (err) {
        console.log(err || 'no error');
        process.exit();
    });
});

cc and bcc

Is it possible to send copy carbon, and blind copy carbon?
The current implementation doesn't seem to send one message to two recipients, unless you use a mailing list

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.