我需要我的应用程序来发送电子邮件,所以我遇到了nodemailer,简单和快速的解决方案。我试过了,在node app.js
之后,电子邮件就被发送了。太棒了。
现在,我想要我的web应用程序发送电子邮件,因为require
没有在浏览器端定义,所以我最终读到了browserify
,commonJS
,最后是requireJS
。
我在简单的.js
文件中尝试过,它看起来非常简单。现在我正忙于让它与存储我的nodemailer
模块的文件夹node_modules一起工作。
我该怎么做呢?在docs中,它说我不应该require("./node_modules/foo/foo").
,那么我如何才能require
我的模块呢?我找不到任何完整的例子。
我的应用程序的相关文件的结构如下所示。
Project/index.html
*
Project/js/app.js
//my own mvc app.js, not requireJS's
Project/js/mailer.js
//.js that holds the nodemailer code for sending emails
Project/node_modules/requirejs
//requirejs.js inside
Project/node_modules/nodemailer
//nodemailer module
更新
(因为我花了一整天的时间)
我正在获取找不到nodemailer.js
文件的Uncaught Error: Script error for: nodemailer
。它在根目录中查找它。为什么?requireJS
不会在node_modules中查找它吗?
Index.html
<script
type="text/javascript"
data-main="main"
src="./node_modules/requirejs/require.js">
</script>
Main.js
var nodemailer = require(["nodemailer"],
function(nodemailer){
//email code
}
);
你知道我做错了什么吗?
发布于 2013-11-18 00:44:14
请理解,浏览器有一组特定的功能,直接发送电子邮件不在其中。Browserify只能使一组非常有限的简单nodejs模块在浏览器中运行,但它不能神奇地使浏览器能够读取任意文件、建立任意网络连接、执行DNS查找以及其他显式添加到节点以使其成为服务器环境的内容。围绕这一点,有一些误导性的browserify文档,但是您不能使用任意的节点模块,通过browserify运行它,然后在浏览器中使用它。您需要做一些类似以下内容的工作:
<a href="mailto:...">
链接发送邮件
https://stackoverflow.com/questions/20024004
复制相似问题