Skip to main content

Python email utils

Project description

kmailbox is a python email library, support for sending and receiving emails via SMTP and IMAP protocol。

send plain text email:

from kmailbox import Message, MailBox

msg = Message()
sender = "Tester<test@google.com>"
recipient = "hello@google.com"
msg.subject = "kmailbox test"
msg.content = "This is test"

mailbox = MailBox(smtp_host="smtp.gmail.com", use_tls=True)
mailbox.username = "username"
mailbox.password = "password"
mailbox.send(msg)

send html email:

msg = Message()
sender = "Tester<test@google.com>"
recipient = "hello@google.com"
msg.subject = "kmailbox test send html and add attachments"
msg.is_html = True
msg.content = """\
<body>
<p><img src="cid:0"></p>

<p>Hello! I am <em>Huoty</em>.</p>

<p>How are you?</p>

<p>Give you a picture:</p>
<p><img src="cid:1"></p>
</body>
"""
msg.attachments = [
    "cid0:imgs/mailbox-icon.png",
    "cid1:imgs/20171005170550.jpg",
    "kmailbox.py",
    "README.md"
]

mailbox = MailBox(
    smtp_host="smtp.gmail.com",
    use_ssl=True,
    username="username"
    password="password"
)
mailbox.send(msg)

receive mails:

mailbox = MailBox(imap_host="imap.gmail.com", use_ssl=True)
mailbox.username = "username"
mailbox.password = "password"
mailbox.select()
for mail mailbox.all(mark_seen=False, gen=True)
    pprint({
        "uid": mail.uid,
        "sender": mail.sender,
        "to_addrs": mail.to_addrs,
        "subject": mail.subject,
        "date": str(mail.date),
        "flags": mail.flags,
        "attachments": [att.filename for att in mail.attachments],
    })
mailbox.logout()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kmailbox-0.2.1.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

kmailbox-0.2.1-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file kmailbox-0.2.1.tar.gz.

File metadata

  • Download URL: kmailbox-0.2.1.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0.post20201207 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.5

File hashes

Hashes for kmailbox-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fe2c7004a0e5ef298b5ab91207a3a984a22c7205d36b22f389df98459eb5f796
MD5 e6e6156572752d167b24249e6a21a706
BLAKE2b-256 f0b94d7ddb721c3bbd1f549b0e82897fe8501855a304b4c634360ddbbddae530

See more details on using hashes here.

File details

Details for the file kmailbox-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: kmailbox-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0.post20201207 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.5

File hashes

Hashes for kmailbox-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 93d58664038c316c02c8d1052cfea46d8bd87638be514a8e3a567ee95ef2be91
MD5 7e186af3d345e50765994b6faeaec81e
BLAKE2b-256 beadf230c865b947045aec7503032b575b1e5b2dcfbfb7037f22080bd2de357c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page