Skip to main content

About this module

Simple imap wrapper.

Latest Version Supported Python versions License

Example to use

connect function create IMAP4_SSL instance by default:

>>> import easyimap
>>> host = "imap.gmail.com"
>>> user = "me@example.com"
>>> password = "hogehogehogehoge"
>>> mailbox = "secret"
>>> imapper = easyimap.connect(host, user, password, mailbox)

connect function also create IMAP4 instance by passing ssl argument:

>>> import easyimap
>>> host = "imap.gmail.com"
>>> user = "me@example.com"
>>> password = "hogehogehogehoge"
>>> mailbox = "secret"
>>> imapper = easyimap.connect(host, user, password, mailbox, ssl=False, port=143)

This imapper can list up latest n mail by listup method. By default, This invoke fetch from IMAP4_SSL instance with ‘(UID RFC822)’.:

>>> mail1, mail2 = imapper.listup(2)
>>> mail1.uid
80
>>> mail1
<easyimap.easyimap.MailObj object at 0x...>
>>> type(mail1.body)
<type 'unicode'>
>>> type(mail1.title)
<type 'unicode'>
>>> type(mail1.date)
<type 'unicode'>
>>> type(mail1.sender)
<type 'unicode'>

You can check latest unseen mail by unseen method:

>>> imapper.unseen(2)
[(82, <easyimap.easyimap.MailObj object at 0x...>), (81, <easyimap.easyimap.MailObj object at 0x...)]

You can directly fetch email object with specific id:

>>> imapper.mail(80)
<easyimap.easyimap.MailObj object at 0x...>

You can download attachments:

>>> imapper.mail(80)
>>> (id, mail) = imapper.mail(80)
>>> for attachment in mail.attachment:
>>>     print attachment[0], attachment[1]

Finally, call quit method:

>>> imapper.quit()

Basic API

  • easyimap.connect(host, user, password, mailbox=’INBOX’, timeout=15, ssl=True, port=993, **kwargs)
    Create IMAP4(_SSL) wrapper.
    If you want to keep read/unread status, Please pass optional read_only=True argument.
    kwargs are read from Imapper’s constructor. Plz read source code.

Imapper

  • listids(limit=10, criterion=None)

    Returns list of available email ids.

  • listup(limit=10, criterion=None, include_raw=False)

    Returns list of mail_object.

  • unseen(limit=10)

    Returns list of mail_object.

  • mail(uid, include_raw=False)

    Returns MailObj.

  • change_mailbox(mailbox)

    Change mailbox.

  • quit()

    Close and Logout.

MailObject

  • uid

    Returns UID(type: int).

  • raw

    if you fetched email with include_raw option, this returns raw Data:

    >>> [(id1, mail1), (id2, mail2)] = imapper.listup(2, include_raw)
    >>> data = mail1.raw
  • title

    Returns string of ‘Subject’ header.

  • sender

    Returns string of ‘Sender’ header.

  • from_addr

    Returns string of ‘From’ header.

  • to

    Returns string of ‘To’ header.

  • date

    Returns string of ‘Date’ header.

  • body

    Returns string of Body.

  • content_type

    Returns string of ‘Content-Type’ header.

  • content_transfer_encoding

    Returns string of ‘Content-Transfer-Encoding’ header.

  • references

    Returns string of ‘References’ header.

  • in_reply_to

    Returns string of ‘In-Reply-To’ header.

  • reply_to

    Returns string of ‘Reply-To’ header.

  • return_path

    Returns string of ‘Return-Path’ header.

  • mime_version

    Returns string of ‘MIME-Version’ header.

  • message_id

    Returns string of ‘Message-ID’ header.

  • attachments

    Returns list of tuples(‘attached file name’, MailObj).

Recent Change

  • 0.6.3
    • Add support for python-3.5.

    • Fixed a bug in decoding an attached plain text.

  • 0.6.2
    • Fixed a bug in header/body encoding

  • 0.6.1
    • Fixed a bug in _decode_header function

  • 0.6.0
    • Add support for Python-3.4.

    • Backward incompatible changes
      • Modify listup to return list of mailobj.

      • Rename many properties to underbar separated format.

Metadata

Release files for easyimap 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for easyimap 0.7.0
File Size Uploaded
easyimap-0.7.0.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for easyimap 0.7.0
File Interpreter ABI Platform
easyimap-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.6 kB

Release files / easyimap-0.7.0.tar.gz

Download URL easyimap-0.7.0.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6c2700d92d830de41c7012a0c76ac5ed9b46a04b929a6f7f9b578dd9dea8f725
BLAKE2b-256 checksum
How to use checksums
48090921c7411d55c7e1defbbf00dbf009d78ed382e277e54505058f4fe3d1ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

Release files / easyimap-0.7.0-py3-none-any.whl

Download URL easyimap-0.7.0-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9898a5c63dec32ac7b63cb111fed62ad47bb5aa6245f70285e3f6194e3e9adaf
BLAKE2b-256 checksum
How to use checksums
3f2deb58f09ad7d4d9d9604d741366c7b734a69a1e7ce372b60cb149009defd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.3

2 release files

0.6.2

1 release file

0.6.1

1 release file

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page