is it possible to send email with casperjs?

允我心安 提交于 2019-12-12 04:02:55

问题


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('no-reply@at.com',
     ['myemail@gmail.com'],
     '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


回答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'
    }
});


来源:https://stackoverflow.com/questions/35296910/is-it-possible-to-send-email-with-casperjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!