# Read email from your app

> Let an app collect replies, orders or support mail from a veldhost mailbox over IMAP with an Email API key.

Source: https://veldhost.eu/docs/read-email-from-your-app

Last verified: 2026-11-16

Your app reads a mailbox over IMAP, signed in with an Email API key that may **Read mail** or **Change mail**. Use it to collect replies, incoming orders or support requests.

## Before you start

[Create an Email API key](https://veldhost.eu/docs/email-api-keys) on the mailbox and choose what the app needs:

- **Read mail**: the app can list, search and download messages and attachments. It changes nothing: messages stay unread, nothing is moved or deleted. Commands that would change something either do nothing or are refused.
- **Change mail**: everything **Read mail** can do, plus marking messages read or flagged, moving them between folders, deleting them and saving drafts. Choose this when the app should mark what it has processed.

## Settings

| Setting | Value |
|---|---|
| Server | imap.veldhost.eu |
| Port | 993 |
| Security | SSL/TLS |
| Username | the mailbox address |
| Password | the Email API key |

Email API keys sign in over IMAP only. POP3, mail filters (ManageSieve), calendars and contacts do not accept them.

## Examples

`MAILBOX` is the mailbox address, `KEY` the Email API key, `IMAP_HOST` stands for imap.veldhost.eu and `IMAP_PORT` for 993.

**Python** (read new mail, mark it processed; needs **Change mail**):

```python
import imaplib, os, email

with imaplib.IMAP4_SSL("IMAP_HOST", IMAP_PORT) as imap:
    imap.login("MAILBOX", os.environ["EMAIL_API_KEY"])
    imap.select("INBOX")
    _, ids = imap.search(None, "UNSEEN")
    for num in ids[0].split():
        _, data = imap.fetch(num, "(RFC822)")
        message = email.message_from_bytes(data[0][1])
        print(message["From"], message["Subject"])
        imap.store(num, "+FLAGS", "\\Seen")
```

With a **Read mail** key, open the mailbox read-only (`imap.select("INBOX", readonly=True)`) and keep track of what you processed yourself, for example by the message's UID.

**Node.js** (imapflow):

```js
const client = new ImapFlow({ host: 'IMAP_HOST', port: IMAP_PORT, secure: true,
  auth: { user: 'MAILBOX', pass: process.env.EMAIL_API_KEY } });
await client.connect();
const lock = await client.getMailboxLock('INBOX');
try {
  for await (const msg of client.fetch({ seen: false }, { envelope: true })) {
    console.log(msg.envelope.from[0].address, msg.envelope.subject);
  }
} finally { lock.release(); await client.logout(); }
```

**PHP**: any IMAP library (for example webklex/php-imap) with the settings above.

## Good habits

- Check for new mail every minute or two, or keep one connection open and use IDLE. Do not log in for every message.
- Reading over IMAP is included in your plan and is not billed.
- Download large attachments once and keep them; do not fetch the same message again and again.

## Related

- [Email API keys](https://veldhost.eu/docs/email-api-keys)
- [Send email from your app](https://veldhost.eu/docs/send-email-from-your-app)
- [Email API pricing](https://veldhost.eu/docs/email-api-pricing)