از الگوهای Handlebars با پسوند Trigger Email استفاده کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
اگر در طول پیکربندی برنامه افزودنی، پارامتر «مجموعه قالبها» را مشخص کردهاید، میتوانید الگوهای قالبهای Handlebars را برای ایمیلهای خود ایجاد و مدیریت کنید.
ساختار مجموعه الگو
به هر سند یک شناسه به یاد ماندنی بدهید که به عنوان نام الگو در اسنادی که در مجموعه الگوهای خود می نویسید استفاده می کنید.
سند الگو می تواند شامل هر یک از فیلدهای زیر باشد:
- موضوع: یک رشته الگو برای موضوع ایمیل.
- text: یک رشته الگو برای محتوای متن ساده ایمیل.
- html: یک رشته الگو برای محتوای HTML ایمیل.
- amp: یک رشته الگو برای محتوای AMP4EMAIL ایمیل.
- پیوست ها: آرایه ای از پیوست ها با رشته های الگو به عنوان مقادیر. گزینه های Nodemailer پشتیبانی می شوند: رشته utf-8، نوع محتوای سفارشی، URL، رشته رمزگذاری شده، URI داده و گره MIME از پیش تولید شده (دقت داشته باشید که ایمیل شما به سیستم فایل سرور ابری دسترسی ندارد).
یک الگوی نمونه ممکن است دارای شناسه following
و محتوایی مانند:
{
subject: "@{{username}} is now following you!",
html: "Just writing to let you know that <code>@{{username}}</code> ({{name}}) is now following you.",
attachments: [
{
filename: "{{username}}.jpg",
path: "{{imagePath}}"
}
]
}
با استفاده از قالب ها ایمیل ارسال کنید
برای ارسال ایمیل با استفاده از الگوها، هنگام افزودن اسناد به مجموعه نامههای خود، یک فیلد template
با name
و ویژگیهای data
اضافه کنید. به عنوان مثال، با استفاده از الگوی following
از بالا:
admin
.firestore()
.collection("MAIL_COLLECTION")
.add({
toUids: ["abc123"],
template: {
name: "following",
data: {
username: "ada",
name: "Ada Lovelace",
imagePath: "https://example.com/path/to/file/image-name.jpg"
},
},
});
جزییات الگو
با تعیین {partial: true}
در سند الگو، میتوانید الگوها را با استفاده از پارتیشنهای قابل استفاده مجدد بنویسید. هر یک از فیلدهای داده استاندارد ( subject
، html
، text
، و amp
) به عنوان قسمتی تعریف می شود که فقط در محیط خود استفاده می شود. به عنوان مثال، پاورقی جزئی به نام footer
ممکن است دارای داده هایی مانند:
{
partial: true,
html: "<p>This mail was sent by ExampleApp, Inc. <a href='https://example.com/unsubscribe'>Unsubscribe</a></p>",
text: "This mail was sent by ExampleApp, Inc. Unsubscribe here: https://example.com/unsubscribe"
}
در یک الگوی دیگر، جزئی را با ارجاع به نام آن (شناسه سند) وارد کنید:
<p>This is my main template content, but it will use a common footer.</p>
{{> footer }}
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی."],[],[],null,["\u003cbr /\u003e\n\nIf you specified a \"Templates collection\" parameter during configuration of the\nextension, you can create and manage [Handlebars templates](https://handlebarsjs.com/)\ntemplates for your emails.\n\nTemplate collection structure\n\nGive each document a memorable ID that you use as the *template name* in the\ndocuments you write to your templates collection.\n\nThe template document can include any of the following fields:\n\n- **subject:** A template string for the subject of the email.\n- **text:** A template string for the plaintext content of the email.\n- **html:** A template string for the HTML content of the email.\n- **amp:** A template string for the [AMP4EMAIL](https://amp.dev/documentation/guides-and-tutorials/learn/email-spec/amp-email-format/) content of the email.\n- **attachments:** An array of attachments with template strings as values; [Nodemailer options](https://nodemailer.com/message/attachments/) supported: utf-8 string, custom content type, URL, encoded string, data URI, and pre-generated MIME node (be aware that your email has no access to the cloud server's file system).\n\nAn example template might have an ID of `following` and content like: \n\n {\n subject: \"@{{username}} is now following you!\",\n html: \"Just writing to let you know that \u003ccode\u003e@{{username}}\u003c/code\u003e ({{name}}) is now following you.\",\n attachments: [\n {\n filename: \"{{username}}.jpg\",\n path: \"{{imagePath}}\"\n }\n ]\n }\n\nSend emails using templates\n\nTo deliver email using templates, when adding documents to your mail collection,\ninclude a `template` field with `name` and `data` properties. For example,\nusing our `following` template from above: \n\n admin\n .firestore()\n .collection(\"MAIL_COLLECTION\")\n .add({\n toUids: [\"abc123\"],\n template: {\n name: \"following\",\n data: {\n username: \"ada\",\n name: \"Ada Lovelace\",\n imagePath: \"https://example.com/path/to/file/image-name.jpg\"\n },\n },\n });\n\nTemplate Partials\n\nYou can compose templates using reusable [partials](https://handlebarsjs.com/guide/partials.html)\nby specifying `{partial: true}` in the template document. Each of the standard\ndata fields (`subject`, `html`, `text`, and `amp`) will be defined as a partial\nused only in its own environment. For example, a partial called `footer` might\nhave data like: \n\n {\n partial: true,\n html: \"\u003cp\u003eThis mail was sent by ExampleApp, Inc. \u003ca href='https://example.com/unsubscribe'\u003eUnsubscribe\u003c/a\u003e\u003c/p\u003e\",\n text: \"This mail was sent by ExampleApp, Inc. Unsubscribe here: https://example.com/unsubscribe\"\n }\n\nIn another template, include the partial by referencing its name (document ID): \n\n \u003cp\u003eThis is my main template content, but it will use a common footer.\u003c/p\u003e\n\n {{\u003e footer }}"]]