有没有跑通用云函数发邮件的大佬
发布于 6 年前 作者 xtang 2418 次浏览 来自 问答

我用了nodemailer,但是报错,说是超时。

请问有没有大佬成功用云函数发过邮件?

2 回复

sendmail函数的代码如下:

  • index.js

// 云函数入口文件const nodemailer = require("nodemailer");var transporter = nodemailer.createTransport({
  service: 'qq',
  port: 465,               // SMTP 端口
  secure: true,            // 使用 SSL
  auth: {
    user: '[email protected]',   //发邮件邮箱
    pass: '*******'        //此处不是qq密码是
  }});var mailOptions = {
 from: '[email protected]',   // 发件地址
  to: '[email protected]',    // 收件列表
  subject: '测试云函数',      // 标题
  text: '测试云函数'};// 云函数入口函数exports.main = async (event, context) => {
  console.log("Start to sendemail")
 //开始发送邮件
 const info = await transporter.sendMail(mailOptions);
  console.log('Message sent: ' + info.response);
 return info}
  • package.json

{
 "name": "sendmail",
 "version": "1.0.0",
 "description": "",
 "main": "index.js",
 "scripts": {
 "test": "echo \"Error: no test specified\" && exit 1"
  },
 "author": "",
 "license": "ISC",
 "dependencies": {
 "wx-server-sdk": "latest",
 "nodemailer":"^4.7.0"    //在此处注明要使用的nodemailer库,上传云函数的时候后台可以自动部署
  }}

需要修改下index.js里的邮箱地址,然后在微信IDE里右键选择“上传并部署(云端安装依赖)”。

出现下面的错误,哪位大佬知道怎么解决

{“errorCode”:1,“errorMessage”:“user code exception caught”,“stackTrace”:“connect ECONNREFUSED 127.0.0.1:25”}

回到顶部