-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Updates Email Routing docs #20491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Updates Email Routing docs #20491
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
90972fb
Updates postmaster page
celso d156a0e
formatting
celso 3d535b5
updates outbound hostnames
celso b969e9f
better language
celso 388eca6
New reply rules and limits
celso b0318d0
adds changelog
celso 84501d6
clarifies headers
celso c8622ee
Update src/content/changelog/email-routing/2025-03-12-reply-limits.mdx
celso eeda4b4
Update src/content/changelog/email-routing/2025-03-12-reply-limits.mdx
celso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/content/changelog/email-routing/2025-03-12-reply-limits.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| --- | ||
| title: Threaded replies now possible in Email Workers | ||
| description: You can now use Email Workers to send multiple replies to the same email thread. | ||
| date: 2025-03-12T18:00:00Z | ||
| preview_image: ~/assets/images/changelog/ai-gateway/guardrails-social-preview.png | ||
| --- | ||
|
|
||
| Due to increased demand for email use in AI Agents and other forms of task automation, we changed the rules and limits of how Email Workers can [reply](/email-routing/email-workers/reply-email-workers/) to incoming emails. | ||
celso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| It's now possible to keep a threaded email conversation with an [Email Worker](/email-routing/email-workers/) script as long as: | ||
|
|
||
| * The incoming email has to have valid [DMARC](https://www.cloudflare.com/learning/dns/dns-records/dns-dmarc-record/). | ||
| * The email can only be replied to once in the same `EmailMessage` event. | ||
| * The recipient in the reply must match the incoming sender. | ||
| * The outgoing sender domain must match the same domain that received the email. | ||
| * Every time an email passes through Email Routing or another MTA, an entry is added to the `References` list. We stop accepting replies to emails with more than 100 `References` entries to prevent abuse or accidental loops. | ||
|
|
||
| Here's an example of a Worker responding to Emails using a Workers AI model: | ||
|
|
||
| ```ts title="AI model responding to emails" | ||
| import PostalMime from "postal-mime"; | ||
| import {createMimeMessage} from "mimetext" | ||
| import { EmailMessage } from "cloudflare:email"; | ||
|
|
||
| export default { | ||
| async email(message, env, ctx) { | ||
| const email = await PostalMime.parse(message.raw) | ||
| const res = await env.AI.run('@cf/meta/llama-2-7b-chat-fp16', { | ||
| messages: [{ | ||
| role: "user", | ||
| content: email.text ?? '' | ||
| }] | ||
| }) | ||
|
|
||
| // message-id is generated by mimetext | ||
| const response = createMimeMessage() | ||
| response.setHeader("In-Reply-To", message.headers.get("Message-ID")!); | ||
| response.setSender("[email protected]"); | ||
| response.setRecipient(message.from); | ||
| response.setSubject("Llama response"); | ||
| response.addMessage({ | ||
| contentType: 'text/plain', | ||
| data: res instanceof ReadableStream ? await new Response(res).text() : res.response! | ||
| }) | ||
|
|
||
| const replyMessage = new EmailMessage("<email>", message.from, response.asRaw()); | ||
| await message.reply(replyMessage) | ||
| } | ||
| } satisfies ExportedHandler<Env>; | ||
| ``` | ||
|
|
||
| See [Reply to emails from Workers](/email-routing/email-workers/reply-email-workers/) for more information. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.