Get an API key
Mailbox

messages.get()

mailbox.messages.get(id) → Promise<Message>

The whole message: text, HTML, copies and attachments — each attachment with a signed link that lasts fifteen minutes.

freelinks last 15 minutesnever render sender HTML
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

const message = await box.messages.get(id);

message.from;          // { address, name, avatar, avatarSource }
message.text;
message.attachments;   // [{ id, name, size, mime, inline, contentId, url }]
message = box.messages.get(message_id)

message["from"]          # {"address", "name", "avatar", "avatarSource"}
message["text"]
message["attachments"]   # [{"id", "name", "size", "mime", "inline", "contentId", "url"}]

Never render a sender's HTML

It is someone else's HTML in your page

Strip it to text, or render it in something that cannot execute. Anyone can send a message, which makes this the most obviously hostile input a product has.

// A reader left open must renew
setInterval(() => box.messages.get(openId).then(render), 12 * 60_000);
import threading

# A reader left open must renew its signed links
def renew():
    render(box.messages.get(open_id))
    threading.Timer(12 * 60, renew).start()

renew()

Past that, images break and downloads are refused while the bytes are perfectly safe. Re-read the message every twelve minutes, and when a tab comes back.

inline alone does not mean « already shown »

Hide a part only when the body cites its contentId

Some senders mark every attachment as inline with an identifier, even when the body refers to none of them. A reader that hides on the flag alone hides the photo from the list while the body shows nothing — it disappears twice.

url can be null

The bytes could not be stored — a full quota, or a part that was too large. The attachment is still described, and an honest page says « not available » rather than offering a dead link. A message is never lost for it.

The sender's picture

from.avatar, with avatarSource saying whether it is from your address book or from the sender's domain. Nothing at all when neither exists — keep initials for that.