收藏
回答

为什么使用云函数发送邮件报错?Error: cloud.callFunction:fail -404

报错信息:

发送失败 Error: cloud.callFunction:fail -404011 cloud function execution error. 云函数执行错误

云端堆栈信息(error stack)(callid 1626345888216-0.5747384957329358):

Error: collection.get:fail -501001 resource system error. Environment not found

    at Object.toSDKError (:27751/var/user/node_modules/wx-server-sdk/index.js:8089)

    at Object.checkError (:27751/var/user/node_modules/wx-server-sdk/index.js:1422)

    at Promise (:27751/var/user/node_modules/wx-server-sdk/index.js:1489)

    at process._tickCallback (:27751/appservice/internal/process/next_tick.js:68)我晕了 今天上午十点还可以发送 下载再用就不行了 神仙救救我吧!

云函数

const cloud = require('wx-server-sdk')
cloud.init({
  env:cloud.DYNAMIC_CURRENT_ENV
})
//引入发送邮件的类库
var nodemailer = require('nodemailer')
// 创建一个SMTP客户端配置
var config = {
  host'smtp.qq.com'//网易163邮箱 smtp.163.com
  port465//网易邮箱端口 25
  auth: {
    user'838618033@qq.com'//邮箱账号
    pass'befoglzjsndqbbgg' //邮箱的授权码
  }
};
// 创建一个SMTP客户端对象
var transporter = nodemailer.createTransport(config);
// 云函数入口函数
exports.main = async(event, context) => {
  // 创建一个邮件对象
  var mail = {
    // 发件人
    from'来自小程序管理员 <838618033@qq.com>',
    // 主题
    subject'有一位车主拨打了维修店电话',
    // 收件人
    to'838618033@qq.com',
    // text:'姓名为曹博信的车主拨打了维修厂的电话'
    // 邮件内容,text或者html格式
    text:'姓名为'+(await cloud.database().collection('test').get()).data[0].licenceNo+'的车主拨打了维修厂的电话'
  };


  let res = await transporter.sendMail(mail);
  return res;
}

js

Page({
 
  data: {
 
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoadfunction (options{
  },



  sendEmail(){
    wx.cloud.callFunction({
      name:"sendEmail",
      success(res){
        console.log("发送成功",res)
      },
      fail(res){
        console.log("发送失败",res)
      }
    })
  },






  formSubmitfunction (e{
    wx.redirectTo({
      url'/pages/4s/4s',
    })
    console.log('form发生了submit事件,携带数据为:', e.detail.value)
    var data=e.detail.value
   {
        wx.showLoading({
          title'数据正在提交中......',
          mask:"true"
        })
  
        const db = wx.cloud.database()
        db.collection('test').add({
        data: data,
        successres => {
          // 在返回结果中会包含新创建的记录的 _id
          this.setData({
            counterId: res._id
          })
          wx.showToast({
            title'请您拨打电话',
          })
          wx.hideLoading()
         console.log('[数据库] [新增记录] 成功,记录 _id: ', res._id)
        },
        failerr => {
          wx.showToast({
            icon'none',
            title'新增记录失败'
          })
          console.error('[数据库] [新增记录] 失败:', err)
        }
      })
    }
  },


})
最后一次编辑于  2021-07-15
回答关注问题邀请回答
收藏

1 个回答

  • 疯狂的小辣椒
    疯狂的小辣椒
    2021-07-19

    Environment not found,检查下初始化的环境是否正确。

    2021-07-19
    有用
    回复
登录 后发表内容