收藏
回答

云函数调用云函数还有触发器 执行sendEmail smtp报错?

云函数调用云函数还有触发器 我给设了触发器 执行sendEmail 云函数 这几次都是smtp报错 我要改成什么port还是要怎么改设置?

每次一开云开发平台上传云函数那次都能调用云函数 没错 但只要等触发器就会时不时调用报错

{"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"Error: Connection timeout\n at SMTPConnection._formatError (/var/user/node_modules/nodemailer/lib/smtp-connection/index.js:790:19)\n at SMTPConnection._onError (/var/user/node_modules/nodemailer/lib/smtp-connection/index.js:776:20)\n at Timeout.\u003canonymous\u003e (/var/user/node_modules/nodemailer/lib/smtp-connection/index.js:235:22)\n at listOnTimeout (internal/timers.js:549:17)\n at processTimers (internal/timers.js:492:7)","statusCode":430}”

config.json:
"triggers": [ 
    {
      "name": "myTrigger",  
      "type": "timer",
      "config": "0 */30 7-18 * * * *"
      
    }
    
  ]
index.js:
// 云函数入口文件
//触发器规则的时区为 UTC+8 = beijing
const cloud = require('wx-server-sdk')


cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境


const nodemailer = require('nodemailer');


// 创建一个SMTP客户端对象
const transporter = nodemailer.createTransport({
    port: 465,
    secure: true, // use TLS
    service: 'gmail',
    auth: {
        user: 'xxx@gmail.com',
        pass: 'xxxx'
    }
});


// 云函数入口函数
exports.main = async(event, context) => {
  const res_orders = await cloud.callFunction({ //调用云函数getOrders
    name: "getOrders",
    success(res) {
      console.log("云函数读取成功", res.result)
      //that.savaExcel(res.result)
    },
    fail(res) {
      console.log("读取失败", res)
    }
  })
  const res_excel = await cloud.callFunction({ //调用云函数excel
    name: "excel",
    data: {
      userdata: res_orders.result
    },
    success(res) {
      console.log("保存成功", res)
      //that.getFileUrl(res.result.fileID) //暂时不要传下载文件列表
      // get resource ID
      
    },
    fail(res) {
      console.log("保存失败", res)
    }
  })


  //res_excel.result.fileID
  //拿到链接
  const res_URL = await cloud.getTempFileURL({
    fileList: [res_excel.result.fileID],
    success: res => {
      // get temp file URL
      console.log("文件下载链接", res.fileList[0].tempFileURL)

    },
    fail: err => {
      // handle error
    }
  })
  // 创建一个邮件对象
  //let {emaildata} = event
  let emaildata = res_URL.fileList[0].tempFileURL
  const mailOptions = {
    from: 'xxx@gmail.com',
    to: ' xxx@qq.com',
    subject: 'xxxx',
    text: emaildata
  };
  let res = await transporter.sendMail(mailOptions);
  console.log('execute await')
  return res;
}


回答关注问题邀请回答
收藏

2 个回答

  • 跨商通
    跨商通
    2023-08-05

    gmail被墙了吧?

    2023-08-05
    有用
    回复
  • Mr.Zhao
    Mr.Zhao
    2023-08-04

    用163、qq邮箱会超时吗

    2023-08-04
    有用
    回复 2
    • 小玉
      小玉
      2023-08-04
      没试 没法注册qq 163邮箱 。 旧手机号被消了 没法密改
      2023-08-04
      回复
    • Mr.Zhao
      Mr.Zhao
      2023-08-04回复小玉
      旧手机号?
      2023-08-04
      回复
登录 后发表内容