feat(worker): add send_email binding support#975
feat(worker): add send_email binding support#975connyay wants to merge 3 commits intocloudflare:mainfrom
Conversation
Adds a `SendEmail` binding and `EmailMessage` type so workers can dispatch email via the Cloudflare Email Sending service configured under `[[send_email]]` in wrangler.toml. Includes worker-sys bindings for `cloudflare:email`, a runnable example under `examples/send-email`, and integration tests.
Extend the SendEmail binding to cover the public-beta builder overload in
addition to the raw MIME path. Adds `Email`/`EmailBuilder`, `EmailAddress`,
`EmailAttachment` (with `AttachmentContent::{Base64, Binary}`), and
`EmailSendResult { message_id }`. `SendEmail::send` now takes `&Email`;
the raw MIME path moves to `SendEmail::send_mime(&EmailMessage)`.
| // Miniflare's `send_email` binding resolves to `undefined`; real | ||
| // workerd resolves to `{ messageId }`. Tolerate both so local dev | ||
| // with `wrangler dev` doesn't throw on deserialize. |
There was a problem hiding this comment.
|
Duplicate The field comment on
So duplicates silently collapse to the last value instead of being preserved. Two ways to tighten:
(1) is simpler and fine given the runtime can't represent duplicates anyway. |
|
The runtime treats attachment string content as UTF-8 bytes, not base64. The function in edgeworker that feeds the mail stream does this: kj::ArrayPtr<kj::byte> getArrayPtrFromContent(kj::OneOf<kj::String, jsg::BufferSource>& content) {
KJ_SWITCH_ONEOF(content) {
KJ_CASE_ONEOF(string, kj::String) { return string.asBytes(); }
KJ_CASE_ONEOF(buffer, jsg::BufferSource) { return buffer.asArrayPtr(); }
}
}
(Sidebar: the public docs at Suggested fix — rename to reflect actual semanticspub enum AttachmentContent {
Text(String), // sent as UTF-8 bytes on the wire
Bytes(Vec<u8>), // sent as Uint8Array
}with the obvious |
Adds a
SendEmailbinding andEmailMessagetype so workers can dispatch email via the Cloudflare Email Sending service configured under[[send_email]]in wrangler.toml. Includes worker-sys bindings forcloudflare:email, a runnable example underexamples/send-email, and integration tests.