0

I am having a hard time finding examples of how to send an email with casperjs. This is my attempt so far... - I successfully got an API key from Mailgun. - I found 2 npm modules such as 'mailgun', and 'mailgun-js' - I loaded them and verified mailgun is loaded globablly and locally.. When I run my casper file. $ casperjs casper-test.js I get the following error: 'undefined' is not a constructor (evaluating 'new mailgun')

var Mailgun = require('mailgun').Mailgun; var mg = new Mailgun('key-xxxxxxxxxxxxxxxa078a515af'); sendText('[email protected]', ['[email protected]'], 'Testing, casper-test', {'X-Campaign-Id': 'something'}, function(err) { err && console.log(err) }); 

My questions are... Am I even going in the right direction? is casperjs capable of firing off one of these modules? If so please let me know how I can fix

3
  • CasperJS/PhantomJS is not node.js. If you need node.js, then run it. Commented Feb 9, 2016 at 16:21
  • stackoverflow.com/a/24389819/4179009 This answer explains the confusion between CasperJS and node.js NPM modules. They are not the same. That mailgun module is to be used with node.js, not CasperJS Commented Feb 9, 2016 at 16:26
  • so than does anyone know how to send an email from within casperjs? Commented Feb 9, 2016 at 17:35

1 Answer 1

1

Yes, You can do it with http api:

casper.setHttpAuth('api', 'YOUR-SECRET-API-KEY'); casper.thenOpen('https://api.mailgun.net/v3/YOUR-MG-DOMAIN/messages', { method: 'post', data: { 'from': 'mailgun@YOUR-MG-DOMAIN', 'to': 'target', 'subject': 'Hello.', 'text': 'message' } }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.