Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese邮件
Val Town supports both directions: vals can be triggered by incoming mail (email-type vals) and can send mail via .
std/emailVal Town 支持两个方向:val 可以由传入邮件触发(邮件类型的 val),也可以通过 发送邮件。
std/emailReceiving email — email-type vals
接收邮件——邮件类型的 val
Email vals () run when a message is delivered to the val's assigned address.
fileType: "email"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 — for the handler.
exportexport defaultMaximum 30MB per message, including attachments. Larger messages will be rejected.
邮件 val()会在消息投递到为该 val 分配的地址时运行。
fileType: "email"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);
}文件必须包含 ——处理程序需要使用 。
exportexport default每条消息最大 30MB,其中包括附件。更大的消息将被拒绝。
Reading the assigned address
读取分配的地址
When you list files or create an email-type file, the response includes — 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.
links.email列出文件或创建邮件类型的文件时,响应中会包含 ——这是触发该 val 的地址。始终从 API 响应中读取此地址。绝不自行构造电子邮件地址——其格式归平台所有,并且可能发生变化。
links.emailSending email — std/email
std/email发送邮件——std/email
std/emailFor outgoing mail, import from :
std/emailts
import { email } from "https://esm.town/v/std/email";
await email({
to: "user@example.com",
subject: "Hello",
text: "Message body",
});std/emailemailemail({ ... })email.sendtosubjecttexthtmlfromccbccreplyToattachmentsheadersto要发送邮件,请从 导入:
std/emailts
import { email } from "https://esm.town/v/std/email";
await email({
to: "user@example.com",
subject: "Hello",
text: "Message body",
});std/emailemailemail({ ... })email.sendtosubjecttexthtmlfromccbccreplyToattachmentsheaderstoReplying to an incoming message
回复传入消息
Combine the two — read the inbound in an email-type handler, then call to reply:
fromemailts
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!",
});
}将两者结合使用——在邮件类型的处理程序中读取传入消息的 ,然后调用 进行回复:
fromemailts
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 with a sample 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 for delivery errors.
run_fileEmailget_logs编辑邮件类型的 val 后,使用 传入一个示例 负载来手动调用处理程序,而不是等待真实的传入消息。对于仅用于发送的 val,以相同方式运行脚本,并通过 检查投递错误。
run_fileEmailget_logs