Python API Reference
ZohoMailClient
zohomail.client.ZohoMailClient
Async Zoho Mail client for free-tier accounts.
Authenticates via the Zoho web UI using Playwright, then communicates
with Zoho's internal JSON API (ml.do / md.do). The session
cookie is cached at ~/.zohomail_session.pkl and reused on subsequent
calls. If the session expires the client re-authenticates automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
Your Zoho Mail address (e.g. |
required |
password
|
str
|
Your Zoho account login password (not an app password). |
required |
region
|
str
|
Zoho data-centre region — |
'eu'
|
account_id
|
str
|
Internal Zoho account ID. Auto-discovered if omitted. |
''
|
folder_id
|
str
|
Internal Zoho inbox folder ID. Auto-discovered if omitted. |
''
|
session_file
|
Path | None
|
Path for the session cookie cache. Defaults to
|
None
|
Example
client = ZohoMailClient( ... email="you@yourdomain.com", ... password="your_password", ... region="eu", ... ) emails = asyncio.run(client.list_emails(limit=10))
Source code in zohomail/client.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 | |
download_attachments(msg_id, dest_dir, folder=None, include_inline=False)
async
Download a message's attachments into dest_dir.
Metadata and session cookies are collected inside the browser, the
browser is closed, and the files are then fetched over plain HTTP with
those cookies (Chromium runs --single-process, which breaks
in-browser request APIs). TLS is always verified; see _ssl_context
for how the CA bundle is chosen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg_id
|
str
|
Zoho message ID. |
required |
dest_dir
|
str | Path
|
Directory to save into (created if missing). |
required |
folder
|
str | None
|
Folder the message lives in (default Inbox). |
None
|
include_inline
|
bool
|
Also download inline images. Skipped by default. |
False
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
Saved file paths. Files keep their names; duplicates get |
list[Path]
|
|
Raises:
| Type | Description |
|---|---|
ZohoMailError
|
On auth, API, TLS or download failure, or if a downloaded file's size differs from Zoho's metadata. |
Source code in zohomail/client.py
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 | |
get_thread_info(msg_id)
async
Return the minimal headers needed to reply to a message.
A lightweight alternative to :meth:read_email when you only need
to send a reply and don't need the body.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg_id
|
str
|
The Zoho message ID. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dict with |
Raises:
| Type | Description |
|---|---|
ZohoMailError
|
If authentication or the API call fails. |
Source code in zohomail/client.py
list_emails(limit=10, folder=None, conversations=False)
async
List the most recent inbox messages.
Authenticates if needed, then returns a list of email summaries sorted newest-first. The inbox data is captured from network traffic during page load, so no extra API call is made.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Maximum number of messages to return. Defaults to |
10
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
A list of dicts, each containing: |
list[dict]
|
|
list[dict]
|
|
list[dict]
|
|
list[dict]
|
|
list[dict]
|
|
list[dict]
|
|
Raises:
| Type | Description |
|---|---|
ZohoMailError
|
If authentication or the API call fails. |
Example
emails = asyncio.run(client.list_emails(limit=5)) for e in emails: ... print(e["subject"], "-", e["from"])
Source code in zohomail/client.py
read_email(msg_id, folder=None)
async
Read the full content of a single email.
Fetches the complete message including HTML body, sender details, and threading headers needed for replies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg_id
|
str
|
The Zoho message ID ( |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dict containing: |
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
|
Raises:
| Type | Description |
|---|---|
ZohoMailError
|
If authentication or the API call fails. |
Example
email = asyncio.run(client.read_email("1782000221530004400")) print(email["body"])
Source code in zohomail/client.py
send
zohomail.smtp.send(from_addr, app_password, to, subject, body, *, region='eu', from_name='', cc=None, html=False, in_reply_to='', references='')
Send an email via Zoho SMTP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_addr
|
str
|
Sender address — must match the authenticated Zoho account. |
required |
app_password
|
str
|
App-specific password generated in Zoho Security settings. |
required |
to
|
list[str]
|
List of recipient email addresses. |
required |
subject
|
str
|
Email subject line. |
required |
body
|
str
|
Email body — plain text, or HTML if |
required |
region
|
str
|
Zoho data-centre — |
'eu'
|
from_name
|
str
|
Display name shown to recipients, e.g. |
''
|
cc
|
list[str] | None
|
Optional list of CC addresses. |
None
|
html
|
bool
|
If |
False
|
in_reply_to
|
str
|
RFC 2822 |
''
|
references
|
str
|
Override the |
''
|
Returns:
| Type | Description |
|---|---|
dict
|
A dict with {"status": "sent", "to": ["a@b.com"], "subject": "Hello"} |
Raises:
| Type | Description |
|---|---|
SMTPException
|
On connection or authentication failure. |
Example
from zohomail.smtp import send send( ... from_addr="you@yourdomain.com", ... app_password="xxxx-xxxx", ... to=["friend@example.com"], ... subject="Hello", ... body="Hi there!", ... )
Source code in zohomail/smtp.py
Exceptions
zohomail.client.ZohoMailError
zohomail.client.SessionExpiredError
Bases: ZohoMailError
Raised when the Zoho session expires and re-authentication fails.
Built by MelkonTech