发送带有命名收件人地址的电子邮件
除了现有的 from 支持外,您现在还可以在发送电子邮件时为收件人地址添加显示名称。为 to、cc、bcc、replyTo 或 from 传递一个包含 email 和可选 name 字段的对象:
export default {
async fetch(request, env) {
const response = await env.EMAIL.send({
from: { email: "support@example.com", name: "Support Team" },
to: { email: "jane@example.com", name: "Jane Doe" },
cc: [
"manager@company.com",
{ email: "team@company.com", name: "Engineering Team" },
],
subject: "Welcome!",
html: "<h1>Thanks for joining!</h1>",
text: "Thanks for joining!",
});
return Response.json({ messageId: response.messageId });
},
};export default {
async fetch(request, env): Promise<Response> {
const response = await env.EMAIL.send({
from: { email: "support@example.com", name: "Support Team" },
to: { email: "jane@example.com", name: "Jane Doe" },
cc: [
"manager@company.com",
{ email: "team@company.com", name: "Engineering Team" },
],
subject: "Welcome!",
html: "<h1>Thanks for joining!</h1>",
text: "Thanks for joining!",
});
return Response.json({ messageId: response.messageId });
},
} satisfies ExportedHandler<Env>;为实现向后兼容,纯字符串形式仍受到完整支持,并且您可以在同一个数组中混合使用字符串和命名对象。
有关完整的请求示例,请参阅 Workers API 和 REST API 文档。