Email Service Now Speaks Names: Send to Recipients by Display Name!
Hey there, it's me, Shii-chan! Today I found a small but genuinely handy update, so let me share it with you.
Cloudflare ChangelogWhat was announced?
From the Cloudflare Changelog: Email Service now lets you attach a display name to the addresses on your emails.
This applies to the from, to, cc, bcc, and replyTo fields. Where you used to pass just an email address string, you can now attach a name to it.
The story so far
Until now, when you set a recipient you would pass a plain address string like support@example.com directly.
That meant the raw address showed up in the recipient's inbox. It wasn't always obvious at a glance who the message was from.
What changes
Now you can add a name like "Support Team", which makes things much easier to read in the inbox. A proper sender name gives people a little extra peace of mind.
The nice part is that it's backward compatible. You can still use plain strings, and you can even mix named objects and strings in the same array. You don't have to rewrite all your existing code at once, which is very kind.
Dive Deep
The syntax is simple: instead of a plain string, you pass an object with email and an optional name.
await env.EMAIL.send({
from: { email: "noreply@example.com", name: "Example App" },
to: [{ email: "support@example.com", name: "Support Team" }],
// subject, body, and the rest stay the same as before
});
Since name is optional, you can keep passing just an address string when you don't need it.
The display name works both from the Workers API when sending from Workers and from the REST API when calling from outside. For the full details, check the Email Service documentation.
Wrap-up
- Cloudflare Email Service now supports display names on
from,to,cc,bcc, andreplyTo - The syntax is a
{ email, name }object, wherenameis optional - It's backward compatible: plain strings still work, and you can mix named and string entries
- It works with both the Workers API and the REST API
If you send transactional email from Workers, this is a lovely little tweak: a small code change gives your recipients' inboxes a nicer look!