我需要 OAuth - Google 联系表数据(全部)到 Sheet 然后到电子邮件

Do I need OAuth - Google Contact Form data (all) to Sheet then to Email

我想使用 Google 表格作为网站上的联系表格,并将表格内容(不仅仅是通知)通过电子邮件发送到指定地址。

我创建了一个 Google 表格,并将其嵌入到网站中用作查询联系表格。然后创建一个 Sheet 以从表单中提取数据。之后,我为 onFormSubmission 创建了一个触发器,它运行以下命令:

/**
 * @OnlyCurrentDoc
 */
function onFormSubmission (e) {
  var values = e.namedValues;
  var htmlBody ='<ul>';
  for (Key in values) {
  var label = Key;
  var data = values[Key];
  htmlBody += '<li>' + label + ": " + data + '</li>';
  Logger.log(label + ": " + data);
};
  htmlBody += '</ul>';
  GmailApp.sendEmail('me@gmail.com', 'Web Form Enquiry', '', {htmlBody:htmlBody})
}

运行 这会弹出一个对话框,说明:

Authorization required.

'Send email' needs your permission to access your data on Google Review Permissions or Cancel

['Send email' 是我在 G Suite 中的 'App']

单击“查看权限”会打开一个弹出窗口,要求选择一个帐户以继续。单击该帐户(我登录并创建表单等所用的同一帐户)会出现:

This app isn't verified. This app hasn't been verified by Google yet. Only proceed if you know and trust the developer.

Advanced or Back to safety

点击高级:

Google hasn't reviewed this app yet and can't confirm it's authentic. Unverified apps may pose a threat to your personal data.

Go to 'Send email' (unsafe)

然后说:

'Send email' wants to access your Google account

This will allow 'Send email' to Read, compose, send and permanently delete all your email from Gmail

Connect to an external service (Create a network connection to any external service (e.g. to read or write data)

Make sure that you trust Send emails

You may be sharing sensitive info with this site or app. Find out how Send emails will handle your data by reviewing its terms of service and privacy policies. You can always see or remove access in your Google Account. Find out about the risks

Cancel or Allow

因此,出于测试目的,我单击了“允许”。这一切都很好用!然后我使表单具有响应性,然后我想起我必须返回并检查权限。 4 小时后,我在兔子洞里迷了路,迷茫地爬回了这里。所以我的问题是:

  1. 我需要实施 OAuth 吗?
  2. Google 是否需要验证应用程序?
  3. 如果 2 是肯定的,这需要数周时间吗? (如果是,可能需要放弃这个方案)
  4. 如果我给应用 'permissive permissions'(就像我测试时所做的那样)是否存在任何安全风险?
  5. 如果我给应用程序 'permissive permissions' 是 Google 审查它并决定停止它 运行?
  6. 我能想到需要 OAuth 的唯一原因是数据是从 Sheets 中获取的,正在创建电子邮件并将数据传递给它。是因为数据被传递到与收集它不同的 'service' 吗?或者因为不同的服务正在指示创建电子邮件? (或两者兼而有之?)
  7. 如果实施了 OAuth,这是否意味着将要求用户进行验证?显然,他们不需要登录即可使用网站上的联系表。
  8. 是否可以限制权限,例如仅撰写电子邮件,而不是能够删除帐户中的任何或所有电子邮件(清单?)
  9. 如果我跳过电子表格,即表格到电子邮件,会有什么不同吗? (看不出如何,但为了以防万一。)

这是我第一次使用这些服务,所以希望我已经解释清楚了。

非常感谢收到任何建议!

I want to use Google Form as a contact form on a website, and email the contents of the form (not just a notification) to a specified address.


  1. Do I need to implement OAuth?

您正在做的已经是 OAuth 流程。但它由应用程序脚本管理。所以,没有。

  1. Does Google need to verify the app?

不适用于您的用例。

  1. If yes to 2, does this take weeks? (If yes, probably need to abandon this solution)

也许更多

  1. If I give the app 'permissive permissions' (as I did for testing) is there any security risk?

任何有权访问您的脚本的人(暗示任何对您的传播具有编辑权限的人sheet)都可以更改脚本以将电子邮件从您的帐户发送到任何其他网站或阅读或删除您的电子邮件。因此,请避免为您的 Spreadsheet 或脚本提供编辑权限。

  1. If I give the app 'permissive permissions' is Google going to review it and decide to stop it running?

如果您是唯一的用户,则不会。

  1. The only reason I can imagine that OAuth is needed is that data is being taken from Sheets, an email is being created and the data is being passed to that. Is it because of the data being passed to a different 'service' than collected it? Or because a different service is instructing the creation of an email? (Or both?)

是的。

  1. If OAuth is implemented does this mean that users will be asked to verify? Obviously, they will not require to be logged in to use a contact form on a website.

您是电子邮件、sheet 和表单回复的所有者。只是您需要授权 app/script 代表您执行某些工作,例如 copy/paste。

  1. Is it possible to restrict the permissions eg to only compose emails, rather than have the ability to delete any or all emails in the account

是的。

  • 您可以使用 MailApp 代替 GmailApp
  • 或限制 scopes in apps script manifest 文件:

    https://www.googleapis.com/auth/gmail.send      
    
  1. Would it make any difference if I skipped the spreadsheet ie Form to email? (Can't see how, but asking just in case.)

减少脚本流所需的跃点数有利于安全。但是在请求的 oauth flow/permissions 方面没有太大区别。您可以在表单本身中使用 formsubmission trigger。但是请注意,您需要根据表单提交到表单时提供的事件对象重新设计脚本。这与提供给 spreadsheet onformsubmit.

的事件对象不同