简体   繁体   中英

How to Send Email using CasperJS?

I want to send an email to a user using CasperJS.

Is there any way to do it?

If you are okay with using SpookyJS , which allows you to drive CasperJS from Node.js , then you can use the Gmail API for Node.js to send email.

This will probably be one of your most dependable methods for accomplishing this task.

If it is not possible to use SpookyJS, you can use the underlying PhantomJS Child Process Module which is built underneath CasperJS.

The child_process module allows you to invoke subprocesses and communicate with them via stdin / stdout / stderr. This is useful for tasks such as printing, sending mail, or invoking scripts or programs written in another language (not Javascript).

This will allow you to access the command line on your server via CasperJS to run the email program of your choice.

Here's an example snippet of CasperJS interacting with the command line to execute a Bash program that sends out an email:

var process = require('child_process');

process.execFile('/bin/bash', ['send-email.sh', args1, args2, args3], null, function (err, stdout, stderr) {
  this.log('execFileSTDOUT:', JSON.stringify(stdout), 'debug');
  this.log('execFileSTDERR:', JSON.stringify(stderr), 'debug');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM