إرسال محتوى منظّم
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
مستوى الترميز: مبتدئ
المدة: 20 دقيقة
نوع المشروع: أتمتة باستخدام
مشغّل يستند إلى الأحداث
الأهداف
- فهم ما يفعله الحلّ
- فهم وظائف خدمات "برمجة تطبيقات Google" ضمن الحل
- إعداد النص البرمجي
- شغِّل النص البرمجي.
لمحة عن هذا الحل
إذا كان لديك أنواع مختلفة من المحتوى تريد تقديمه لجمهورك، يمكنك السماح للمستخدمين باختيار المحتوى الذي يتلقّونه منك باستخدام "نماذج Google".
يتيح هذا الحل للمستخدمين اختيار المواضيع التي تهمّهم، ثم يرسل إليهم المحتوى الذي اختاروه تلقائيًا عبر البريد الإلكتروني.

آلية العمل
يثبِّت النص البرمجي مشغّلاً مستندًا إلى الأحداث يتم تنفيذه في كل مرة يرسل فيها المستخدم نموذجًا. مع كل عملية إرسال نموذج، ينشئ النص البرمجي رسالة إلكترونية ويرسلها من نموذج "مستندات Google". تتضمّن الرسالة الإلكترونية اسم المستخدم والمحتوى الذي اختاره. يمكن أن يكون المحتوى الذي تقدّمه من أي نوع طالما أنّه يُشار إليه بعنوان URL.
خدمات "برمجة تطبيقات Google"
يستخدم هذا الحل الخدمات التالية:
- خدمة البرامج النصية: تثبِّت هذه الخدمة المشغّل المستند إلى الأحداث الذي يتم تشغيله عندما يرسل أحد المستخدمين النموذج.
- خدمة المستندات: تفتح نموذج "مستندات Google" الذي يستخدمه النص البرمجي لإنشاء الرسالة الإلكترونية.
- خدمة البريد: تنشئ الرسالة الإلكترونية وترسلها مع اسم المستخدم واختيار المحتوى.
- خدمة جداول البيانات: تضيف تأكيدًا إلى ورقة ردود النموذج بعد أن يرسل النص البرمجي الرسالة الإلكترونية.
المتطلبات الأساسية
لاستخدام هذا النموذج، يجب استيفاء المتطلبات الأساسية التالية:
- حساب Google (قد تتطلّب حسابات Google Workspace موافقة المشرف).
- متصفّح ويب يمكنه الوصول إلى الإنترنت
إعداد النص البرمجي
انقر على الزر أدناه لإنشاء نسخة من جدول بيانات إرسال محتوى منتقى. مشروع "برمجة التطبيقات" الخاص بهذا الحلّ مرتبط بجدول البيانات.
إنشاء نسخة
في جدول البيانات الذي نسخته، انقر على الإضافات
> برمجة التطبيقات.
في القائمة المنسدلة للدالة، اختَر installTrigger.
انقر على تشغيل.
امنح الإذن للنصّ البرمجي عند مطالبتك بذلك.
إذا عرضت شاشة الموافقة على OAuth التحذير لم يتم التحقّق من هذا التطبيق،
يمكنك المتابعة من خلال النقر على خيارات متقدمة >
الانتقال إلى {اسم المشروع} (غير آمن).
ملاحظة مهمة: إذا شغّلت installTrigger أكثر من مرة، سينشئ النص البرمجي مشغّلات متعددة يرسل كل منها رسالة إلكترونية عندما يرسل المستخدم النموذج. لحذف العوامل المشغّلة الإضافية وتجنُّب تلقّي رسائل إلكترونية مكرّرة، انقر على العوامل المشغّلة
alarm. انقر بزر الماوس الأيمن على كل مشغّل إضافي
وانقر على حذف المشغّل.
تشغيل النص البرمجي
- ارجع إلى جدول البيانات وانقر على الأدوات
> إدارة النموذج
> الانتقال إلى النموذج المباشر.
- املأ النموذج وانقر على إرسال.
- تحقَّق من بريدك الإلكتروني بحثًا عن رسالة إلكترونية تتضمّن روابط تؤدي إلى المحتوى الذي اخترته.
مراجعة الرمز البرمجي
لمراجعة رمز Apps Script الخاص بهذا الحلّ، انقر على
عرض رمز المصدر أدناه:
المساهمون
تحتفظ Google بهذا النموذج بمساعدة خبراء Google المطوّرين.
الخطوات التالية
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThis solution uses Google Forms and Apps Script to automatically email curated content to users based on their selected topics.\u003c/p\u003e\n"],["\u003cp\u003eThe script uses an event-driven trigger to run whenever a form is submitted, creating and sending emails from a Google Docs template.\u003c/p\u003e\n"],["\u003cp\u003eYou'll need a Google Account and a web browser to use this solution; setting up involves copying a spreadsheet, installing a trigger in Apps Script, and authorizing the script.\u003c/p\u003e\n"],["\u003cp\u003eTo run the solution, simply open the form, fill it out, submit it, and check your email for the content links.\u003c/p\u003e\n"],["\u003cp\u003eThis solution uses various Apps Script services like Script service, Document service, Mail service, and Spreadsheet service to manage triggers, templates, emails, and responses.\u003c/p\u003e\n"]]],["This Apps Script solution automates sending curated content to users via email based on their Google Forms submissions. Upon each form submission, an event-driven trigger activates the script. The script then uses a Google Docs template to generate a personalized email that includes the user's name and links to content they selected. It uses the Script service to install a trigger, the Document service to open the template, the Mail service to send the email, and the Spreadsheet service to record the sending status.\n"],null,["# Send curated content\n\n**Coding level** : Beginner \n\n**Duration** : 20 minutes \n\n**Project type** : Automation with an\n[event-driven trigger](/apps-script/guides/triggers/installable#event-driven_triggers)\n\nObjectives\n----------\n\n- Understand what the solution does.\n- Understand what the Apps Script services do within the solution.\n- Set up the script.\n- Run the script.\n\nAbout this solution\n-------------------\n\nIf you have various types of content you'd like to offer your audience, you can\nlet users choose what content they receive from you with Google Forms.\nThis solution lets users select the topics they're interested in, then\nautomatically emails them their chosen content.\n\n### How it works\n\nThe script installs an event-driven trigger that runs each time a user submits\na form. With each form submission, the script creates and sends an email from\na Google Docs template. The email includes the user's name and the content they\nselected. The content you offer can be of any type as long as it's referenced by\na URL.\n\n### Apps Script services\n\nThis solution uses the following services:\n\n- [Script service](/apps-script/reference/script)--Installs the event-driven trigger that fires whenever someone submits the form.\n- [Document service](/apps-script/reference/document)--Opens the Docs template that the script uses to create the email.\n- [Mail service](/apps-script/reference/mail)--Creates and sends the email with the user's name and content selection.\n- [Spreadsheet service](/apps-script/reference/spreadsheet)--Adds a confirmation to the **Form responses** sheet after the script sends the email.\n\nPrerequisites\n-------------\n\nTo use this sample, you need the following prerequisites:\n\n- A Google Account (Google Workspace accounts might require administrator approval).\n- A web browser with access to the internet.\n\nSet up the script\n-----------------\n\n1. Click the following button to make a copy of the **Send curated content**\n spreadsheet. The Apps Script project for this\n solution is attached to the spreadsheet.\n\n [Make a copy](https://docs.google.com/spreadsheets/d/1jYee3vEwI_v7tixJY68TH1mzcNuRm4O4O8YvXGsbNgc/copy)\n\n2. In your copied spreadsheet, click **Extensions**\n \\\u003e **Apps Script**.\n\n3. In the function dropdown, select **installTrigger**.\n\n4. Click **Run**.\n\n5. When prompted, authorize the script.\n If the OAuth consent screen displays the warning, **This app isn't verified** ,\n continue by selecting **Advanced** \\\u003e\n **Go to {Project Name} (unsafe)**.\n\n**Important** : If you run **installTrigger** more than once, the script creates\nmultiple triggers that each send an email when a user submits the form. To\ndelete extra triggers and avoid duplicate emails, click **Triggers**\nalarm. Right-click on each extra trigger\nand click **Delete trigger**.\n\nRun the script\n--------------\n\n1. Switch back to the spreadsheet and click **Tools** \\\u003e **Manage form** \\\u003e **Go to live form**.\n2. Fill out the form and click **Submit**.\n3. Check your email for an email with links to the content you selected.\n\nReview the code\n---------------\n\nTo review the Apps Script code for this solution, click\n**View source code** below: \n\n#### View source code\n\n### Code.gs\n\n\u003cbr /\u003e\n\nsolutions/automations/content-signup/Code.js \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/solutions/automations/content-signup/Code.js) \n\n```javascript\n// To learn how to use this script, refer to the documentation:\n// https://developers.google.com/apps-script/samples/automations/content-signup\n\n/*\nCopyright 2022 Google LLC\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n https://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n// To use your own template doc, update the below variable with the URL of your own Google Doc template.\n// Make sure you update the sharing settings so that 'anyone' or 'anyone in your organization' can view.\nconst EMAIL_TEMPLATE_DOC_URL = 'https://docs.google.com/document/d/1enes74gWsMG3dkK3SFO08apXkr0rcYBd3JHKOb2Nksk/edit?usp=sharing';\n// Update this variable to customize the email subject.\nconst EMAIL_SUBJECT = 'Hello, here is the content you requested';\n\n// Update this variable to the content titles and URLs you want to offer. Make sure you update the form so that the content titles listed here match the content titles you list in the form.\nconst topicUrls = {\n 'Google Calendar how-to videos': 'https://www.youtube.com/playlist?list=PLU8ezI8GYqs7IPb_UdmUNKyUCqjzGO9PJ',\n 'Google Drive how-to videos': 'https://www.youtube.com/playlist?list=PLU8ezI8GYqs7Y5d1cgZm2Obq7leVtLkT4',\n 'Google Docs how-to videos': 'https://www.youtube.com/playlist?list=PLU8ezI8GYqs4JKwZ-fpBP-zSoWPL8Sit7',\n 'Google Sheets how-to videos': 'https://www.youtube.com/playlist?list=PLU8ezI8GYqs61ciKpXf_KkV7ZRbRHVG38',\n};\n\n/**\n * Installs a trigger on the spreadsheet for when someone submits a form.\n */\nfunction installTrigger() {\n ScriptApp.newTrigger('onFormSubmit')\n .forSpreadsheet(SpreadsheetApp.getActive())\n .onFormSubmit()\n .create();\n}\n\n/**\n * Sends a customized email for every form response.\n * \n * @param {Object} event - Form submit event\n */\nfunction onFormSubmit(e) {\n let responses = e.namedValues;\n\n // If the question title is a label, it can be accessed as an object field.\n // If it has spaces or other characters, it can be accessed as a dictionary.\n let timestamp = responses.Timestamp[0];\n let email = responses['Email address'][0].trim();\n let name = responses.Name[0].trim();\n let topicsString = responses.Topics[0].toLowerCase();\n\n // Parse topics of interest into a list (since there are multiple items\n // that are saved in the row as blob of text).\n let topics = Object.keys(topicUrls).filter(function(topic) {\n // indexOf searches for the topic in topicsString and returns a non-negative\n // index if the topic is found, or it will return -1 if it's not found.\n return topicsString.indexOf(topic.toLowerCase()) != -1;\n });\n\n // If there is at least one topic selected, send an email to the recipient.\n let status = '';\n if (topics.length \u003e 0) {\n MailApp.sendEmail({\n to: email,\n subject: EMAIL_SUBJECT,\n htmlBody: createEmailBody(name, topics),\n });\n status = 'Sent';\n }\n else {\n status = 'No topics selected';\n }\n\n // Append the status on the spreadsheet to the responses' row.\n let sheet = SpreadsheetApp.getActiveSheet();\n let row = sheet.getActiveRange().getRow();\n let column = e.values.length + 1;\n sheet.getRange(row, column).setValue(status);\n\n console.log(\"status=\" + status + \"; responses=\" + JSON.stringify(responses));\n}\n\n/**\n * Creates email body and includes the links based on topic.\n *\n * @param {string} recipient - The recipient's email address.\n * @param {string[]} topics - List of topics to include in the email body.\n * @return {string} - The email body as an HTML string.\n */\nfunction createEmailBody(name, topics) {\n let topicsHtml = topics.map(function(topic) {\n let url = topicUrls[topic];\n return '\u003cli\u003e\u003ca href=\"' + url + '\"\u003e' + topic + '\u003c/a\u003e\u003c/li\u003e';\n }).join('');\n topicsHtml = '\u003cul\u003e' + topicsHtml + '\u003c/ul\u003e';\n\n // Make sure to update the emailTemplateDocId at the top.\n let docId = DocumentApp.openByUrl(EMAIL_TEMPLATE_DOC_URL).getId();\n let emailBody = docToHtml(docId);\n emailBody = emailBody.replace(/{{NAME}}/g, name);\n emailBody = emailBody.replace(/{{TOPICS}}/g, topicsHtml);\n return emailBody;\n}\n\n/**\n * Downloads a Google Doc as an HTML string.\n * \n * @param {string} docId - The ID of a Google Doc to fetch content from.\n * @return {string} The Google Doc rendered as an HTML string.\n */\nfunction docToHtml(docId) {\n\n // Downloads a Google Doc as an HTML string.\n let url = \"https://docs.google.com/feeds/download/documents/export/Export?id=\" +\n docId + \"&exportFormat=html\";\n let param = {\n method: \"get\",\n headers: {\"Authorization\": \"Bearer \" + ScriptApp.getOAuthToken()},\n muteHttpExceptions: true,\n };\n return UrlFetchApp.fetch(url, param).getContentText();\n}\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nContributors\n------------\n\nThis sample is maintained by Google with the help of Google Developer Experts.\n\nNext steps\n----------\n\n- [Event-driven triggers](/apps-script/guides/triggers/installable#event-driven_triggers)\n- [Spreadsheet service reference](/apps-script/reference/spreadsheet)"]]