Email

作者 val-town2d3ec654b6a7無授權條款收錄於 2026年10月8日更新於 2026年10月8日

Use when a val sends email, receives email, or is triggered by an incoming email. Covers email-type vals (the Email handler shape, attachment limits, the assigned val email address) and sending mail via std/email.

AI 產生的概覽

指導建立可接收來信並透過 std/email 寄送郵件的 Val Town val。

功能
說明 email 類型 val 的處理函式結構,包括 inbound Email 物件的欄位以及每封郵件 30MB 的上限。說明應從 API 回應讀取該 val 被指派的位址,而不是自行組出。介紹如何使用 std/email 的寄送函式寄信以及回覆收到的郵件。也說明如何用範例 payload 手動執行處理函式並查看日誌來驗證變更。
適用情境
當某個 val 需要由來信觸發、寄送郵件或回覆收到的郵件時使用。也適合用來確認附件大小限制或該 val 被指派的電子郵件位址。
執行需求
在 Val Town 上執行;使用從 esm.town 匯入的 std/email 模組以及平台的檔案與日誌 API。此技能未附帶任何指令碼。

Email

Val Town supports both directions: vals can be triggered by incoming mail (email-type vals) and can send mail via std/email.

Receiving email — email-type vals

Email vals (fileType: "email") run when a message is delivered to the val's assigned address.

ts
// Learn more: https://docs.val.town/vals/email/// Email type: {//   from: string,//   to: string[],//   subject?: string,//   text?: string,//   html?: string,//   attachments: File[],//   headers: Record<string, string>// }export default async function (e: Email) {  console.log(e.from, e.subject, e.text);}

The file must have an export — export default for the handler.

Maximum 30MB per message, including attachments. Larger messages will be rejected.

Reading the assigned address

When you list files or create an email-type file, the response includes links.email — the address that triggers this val. Always read this from the API response. Never construct an email address yourself — the format is owned by the platform and may change.

Sending email — std/email

For outgoing mail, import from std/email:

ts
import { email } from "https://esm.town/v/std/email";
await email({  to: "[email protected]",  subject: "Hello",  text: "Message body",});

std/email exports email as the send function itself — call it directly (email({ ... })); there is no email.send method. It accepts the shape you'd expect: to, subject, text, html, plus from, cc, bcc, replyTo, attachments, and headers. If no to field is specified, it defaults to sending mail to the val owner's address.

Replying to an incoming message

Combine the two — read the inbound from in an email-type handler, then call email to reply:

ts
import { email } from "https://esm.town/v/std/email";
export default async function (e: Email) {  await email({    to: e.from,    subject: `Re: ${e.subject ?? ""}`,    text: "Got it, thanks!",  });}

Verifying changes

After editing an email-type val, use run_file with a sample Email payload to invoke the handler manually instead of waiting for a real incoming message. For send-only vals, run the script the same way and check get_logs for delivery errors.

來源與署名

來源:val-town/plugins位於plugin/skills/email提交2d3ec65

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架