You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google AppMaker邮件发送报错求助:点击按钮触发邮件功能失败

Troubleshooting Email Sending Error in Google Apps Script + Client-side Widget

Let's break down how to diagnose and fix this issue step by step:

1. Fix Client-side Error Handling First

Your current client script has a critical issue with error logging—console.text isn't a valid property of the console object. This means you're not seeing the actual error message that's causing the failure, making it impossible to debug properly. Let's fix that first:

function sendEmail(widget){ 
  var item = widget.datasource.item; 
  google.script.run 
    .withFailureHandler(function(error) { 
      // Log the real error details to your browser's console
      console.error('Email sending failed:', error.message);
    }) 
    .withSuccessHandler(function(result) { 
      console.log('Email sent successfully!');
    }) 
    .sendEmails(item); 
}

After updating this, open your browser's developer tools (press F12) and check the Console tab when you click the button. You’ll now get a clear error message pointing to the root cause.

2. Investigate Server-side Issues

Once you have the error message, here are the most common problems to check:

a. Verify item.OwnerEmail is Valid

Double-check that:

  • The field name OwnerEmail matches exactly what’s in your datasource (it’s case-sensitive!)
  • The value stored in OwnerEmail is a valid, non-empty email address
  • You can log the value on the server to confirm it’s being passed correctly:
    function sendEmails(item){ 
      // Log the recipient email to verify it's correct
      console.log('Recipient email:', item.OwnerEmail);
      
      var to = item.OwnerEmail; 
      var subject = 'Please Review'; 
      var body = 'hello<br/>my name is Muhammad Alif bin Azali'; 
      MailApp.sendEmail({ 
        to: to, 
        subject: subject, 
        htmlBody: body, 
        noReply: true 
      }); 
    }
    

You can view these logs in the Google Apps Script editor under View > Logs.

b. Ensure MailApp Permissions are Granted

The first time you run the sendEmails function, you need to authorize it to send emails on your behalf. If you haven’t done this yet:

  1. Open the Google Apps Script editor
  2. Run sendEmails directly (use a test item with a valid email address)
  3. Follow the prompts to grant the necessary permissions

c. Test with Hardcoded Values

To isolate whether the issue is with the item data or the email sending logic itself, temporarily modify the server function to use hardcoded values:

function sendEmails(item){ 
  var to = 'your-test-email@example.com'; // Replace with your own email
  var subject = 'Please Review'; 
  var body = 'hello<br/>my name is Muhammad Alif bin Azali'; 
  MailApp.sendEmail({ 
    to: to, 
    subject: subject, 
    htmlBody: body, 
    noReply: true 
  }); 
}

If this works, the problem is definitely with how you’re retrieving item.OwnerEmail from the datasource.


内容的提问来源于stack exchange,提问作者alep

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:36:39