使用Node.js发送邮件 [英] Send mail with nodejs
本文介绍了使用Node.js发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于一个学校项目,我必须建立一个网站以及所有内容...我想在按下某个按钮时发送电子邮件.目前,我为服务器使用了一个gmail地址,但它需要身份验证以及所有其他功能.如何绕过身份验证?还有其他一些不需要身份验证的STMP服务器,因此我可以轻松发送电子邮件吗?
For a school project I have to build a website and all the stuff... I want to send an email when a certain button is pressed. For now I used an gmail address for the server BUT it needs authentification and all. How can I bypass the authentification ? Are there some other STMP servers that do not require authentification so I send an email easily ?
谢谢大家!
推荐答案
您应使用 Nodemailer
它安装了一个npm模块,然后就可以了.
Its a npm module installed it and there you go.
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'youremail@gmail.com',
pass: 'yourpassword'
}
});
var mailOptions = {
from: 'youremail@gmail.com',
to: 'myfriend@yahoo.com',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
引用: https://www.w3schools.com/nodejs/nodejs_email.asp
这篇关于使用Node.js发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文