puter.email.get()Reads one message by the id a listing returned. The whole raw message is downloaded and parsed, so the result carries the full subject, sender and recipients, the text and HTML bodies, every header, and each attachment with its bytes. Pass raw: true to get the unparsed message/rfc822 bytes as a Blob instead.
Reading the mailbox requires the fs:/{username}/.mail:read permission, the same grant puter.email.list() needs.
puter.email.get(id)
puter.email.get(options)
id (String) (required)
The message id from puter.email.list(). Looks up the inbox.
options (Object)
id (String) (required): The message id.folder (String): 'inbox' or 'sent'. Default 'inbox'. A message id is unique within a folder, so a sent message must be read with folder: 'sent'.raw (Boolean): When true, resolve with the raw message Blob and skip parsing. Default false.A Promise that resolves to an EmailMessage object: the full subject, sender and recipients, the text and HTML bodies, every header, and the attachments as EmailMessageAttachment objects with their decoded bytes.
With raw: true, the Promise resolves to a Blob of the message/rfc822 bytes exactly as they were received.
Messages can be up to 25 MiB, and get() holds the whole message in memory while parsing. For a message list, use puter.email.list() and read messages one at a time as the user opens them.
Rejects with an object carrying a code:
invalid_request: id is missing or not a message id.not_found: no message with that id in the folder.fs:/{username}/.mail:read.Read the newest message in the inbox
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
(async () => {
const { items } = await puter.email.list({ limit: 1 });
if (items.length === 0) return puter.print('Inbox is empty');
const message = await puter.email.get(items[0].id);
puter.print(`From: ${message.from?.name} <${message.from?.address}><br>`);
puter.print(`Subject: ${message.subject}<br>`);
puter.print(`<pre>${message.text}</pre>`);
})();
</script>
</body>
</html>
Save every attachment of a message to the user's Documents
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
(async () => {
const { items } = await puter.email.list({ limit: 1 });
if (items.length === 0) return puter.print('Inbox is empty');
const message = await puter.email.get(items[0].id);
for (const attachment of message.attachments) {
const name = attachment.filename ?? 'attachment';
await puter.fs.write(`~/Documents/${name}`, new Blob([attachment.content], { type: attachment.mimeType }));
puter.print(`Saved ${name} (${attachment.size} bytes)<br>`);
}
})();
</script>
</body>
</html>
Download the raw message
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
(async () => {
const { items } = await puter.email.list({ folder: 'sent', limit: 1 });
if (items.length === 0) return puter.print('Nothing sent yet');
const blob = await puter.email.get({ id: items[0].id, folder: 'sent', raw: true });
const text = await blob.text();
puter.print(`<pre>${text.slice(0, 2000)}</pre>`);
})();
</script>
</body>
</html>