简体   繁体   English

如何使用CasperJS发送电子邮件?

[英]How to Send Email using CasperJS?

I want to send an email to a user using CasperJS. 我想使用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. 如果可以使用SpookyJS允许您从Node.js驱动CasperJS ,则可以使用Gmail API for Node.js发送电子邮件。

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. 如果无法使用SpookyJS,则可以使用在CasperJS下构建的基础PhantomJS子进程模块

The child_process module allows you to invoke subprocesses and communicate with them via stdin / stdout / stderr. child_process模块​​允许您调用子流程并通过stdin / stdout / stderr与之通信。 This is useful for tasks such as printing, sending mail, or invoking scripts or programs written in another language (not Javascript). 这对于诸如打印,发送邮件或调用以另一种语言(非Javascript)编写的脚本或程序的任务很有用。

This will allow you to access the command line on your server via CasperJS to run the email program of your choice. 这将允许您通过CasperJS访问服务器上的命令行以运行您选择的电子邮件程序。

Here's an example snippet of CasperJS interacting with the command line to execute a Bash program that sends out an email: 这是CasperJS与命令行交互以执行发送电子邮件的Bash程序的示例片段:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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