node.js - 使用 gmail 凭据从节点服务器发送电子邮件
问题描述
我希望能够从我的节点服务器发送电子邮件。我创建了一个google developer project
并启用了gmail api
它。gmail api
之后,我以 json 格式下载了凭据。但我无法查找nodemailer
文档,因为该站点似乎已关闭。
如何使用我下载的 gmail 凭据从我的节点服务器发送电子邮件?
解决方案
这是使用 nodemailer 发送邮件的示例代码。使用以下代码创建快递应用程序。
var nodemailer = require("nodemailer");
var smtpTransport = nodemailer.createTransport("SMTP", {
host: 'smtp.gmail.com',
port: 587,
auth: {
user: 'test@gmail.com', //Gamilid that was created by you
pass: 'password'
},
secure: true
});
// app.get('/send',function(req,res){
var mailOptions = {
to: 'sampleto@testcom',
subject: "MAIL TEST",
text: "Hi this is the test mail"
}
console.log(mailOptions);
smtpTransport.sendMail(mailOptions, function (error, response) {
if (error) {
console.log(error);
res.end("error");
} else {
console.log("Message sent: " + response.message);
res.end("sent");
}
});
推荐阅读
- citrix - ica 文件不指向 citrix 接收器
- rust - 如何从 Rust 中的成员函数返回泛型类型
- javascript - React JS:如何将表情符号传递给 Firebase 实时数据库 - 为什么它显示为对象?
- facebook-graph-api - 如何处理 FB messenger API web hook 调用的延迟?
- c# - 加载包含带有反射错误的 Newtonsoft 程序集的 dll
- python - 从嵌套的 HTML 中提取文本内容,同时排除一些特定的标签;刮擦
- amazon-web-services - 这两个端点 URI 映射到哪个 AWS 服务?
- c# - 如何使用 GeckoFX 60 在 C# 上的 DocumentCompleted 事件中获取 http 响应标头?
- ios - 安装了未指定的 Cocoapod 库
- postgresql - 如何通过来自另一个表但不同类型的多个连接记录来过滤数据库表?