最近可能要用到node.js发送邮件;以前同事做过:http://fred.easymorse.com/?p=1235
如果只是在网页里面使用javascript调用邮箱界面的话很简单,在javascript里面一句代码就可以了:
window.location='mailto:sales@witmob.com?subject=To witmob&body=Hello!';
这句代码在网页里面执行之后就可以看到发送邮件的界面:
如果使用 node.js 中的发送邮件则参考下面的方法:
可以直接参看 http://blog.nodejitsu.com/sending-emails-in-node 和 https://github.com/Marak/node_mailer。
下面的方法没有在本服务器中安装邮件服务器,邮件服务器直接使用的是 qq 的。
使用下面的代码就可以实现发送邮件的需求了:
var email = require("mailer");
email.send(
{
ssl: true,
host : "smtp.qq.com",//发送 smtp.qq.com,接收 pop.qq.com
domain : "[xxx.xxx.xxx.xxx]",//可以在浏览器中输入 http://ip.qq.com/ 得到
to : "xxx@qq.com",
from : "xxx@qq.com",
subject : "node_mailer test email",
reply_to: "xxx@qq.com",
body: "Hello! This is a test of the node_mailer.",
authentication : "login",
username : "qq账号",
password : "qq密码",
debug: true
},
function(err, result){
if(err){ console.log("the err: ",err); }
}
);
如果代码中报 454 Authentication failed, please open smtp flag first!\r\n 错,通过下面的方法就可以解决了:
在qq邮箱里面点设置,账户,然后把开启 POP3/SMTP 服务点上,保存就行了
1,设置
2,账户
3,选择 POP3/SMTP,然后保存