Skip to main content

A simplified tool for mailing services

Project description

PyEmailHandler

Receive and Send emails at ease.

Intended for quick and easy projects that does not require specific function other than to receive, send and reply to emails.

Supports:

  • IMAP4
  • SMTP

Basic Usage:

Send a simple Email

from PyEmailHandler import EmailSMTP
email = EmailSMTP(
        username="smtp_username",
        password="smtp_password",
        sender_mail="sender@example.com",
        sender_name="WeSend",
        smtp_server="smtp.example.com",
        port = 587,
        protocol = "starttls"
    )
email.start_connection()
email.send(
    receiver="recipient@mailaddress.com",
    subject="Subject of the e-mail",
    body="Content of the e-mail, can be as long as you want"
)

Send a comprehensive Email

from PyEmailHandler import EmailSMTP
email = EmailSMTP(
        username="smtp_username",
        password="smtp_password",
        sender_mail="sender@example.com",
        sender_name="WeSend",
        smtp_server="smtp.example.com",
        port = 587,
        protocol = "starttls"
    )
email.start_connection()
message = MIMEText(html_text, 'html')
message['Subject'] = "Main subject"
message['To'] = "Recipient Name <recipient@mailaddress.com>"
message['From'] = "WeSend <sender@example.com>"
email.send_raw(
    receiver="recipient@mailaddress.com",
    mime=message
)

Receive Inbox

from PyEmailHandler import EmailIMAP
inbox = EmailIMAP(
        username="imap_username",
        password="imap_password",
        imap_server="imap.example.com",
        port=993,
        protocol="ssl"      
    )
inbox.start_connection()
mails = inbox.get_mails()
for mail in mails:
    print(mail)

Reply to an inbox

By combining Both IMAP and SMTP functionalities

from PyEmailHandler import EmailIMAP, EmailSMTP
from PyEmailHandler.tools import reply_mail
inbox = EmailIMAP(
        username="imap_username",
        password="imap_password",
        imap_server="imap.example.com",
        port=993,
        protocol="ssl"      
    )
inbox.start_connection()
smtp = EmailSMTP(
        username="smtp_username",
        password="smtp_password",
        sender_mail="sender@example.com",
        sender_name="WeSend",
        smtp_server="smtp.example.com",
        port = 587,
        protocol = "starttls"
    )
smtp.start_connection()

mails = inbox.get_mails()
for mail in mails:
    if mail == "Some Criteria here":
        message = MIMEText("Body of Message goes here", "plain")
        #Other headers are handled automatically only the body of the message is required.
        #Some headers are not automatically handled such as the Reply-To header which might be important
        reply_mail(smtp, mail, message)

PROTOCOLS:

ssl
starttls
none #This is unsecure mode, use it at your own discretion

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

pyemailhandler-0.1.3a0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PyEmailHandler-0.1.3a0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file pyemailhandler-0.1.3a0.tar.gz.

File metadata

  • Download URL: pyemailhandler-0.1.3a0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for pyemailhandler-0.1.3a0.tar.gz
Algorithm Hash digest
SHA256 a31d1b75be818df155cd25f360b7a041a9bdef0c0200864a771fa9c9efada09a
MD5 89235bfb35971645ed2afcab4ae50fb4
BLAKE2b-256 f18cdb5cceadb69dd65a1445dabadf9e3d48e86f3b2f8a80b50d0a26f97e72bf

See more details on using hashes here.

File details

Details for the file PyEmailHandler-0.1.3a0-py3-none-any.whl.

File metadata

File hashes

Hashes for PyEmailHandler-0.1.3a0-py3-none-any.whl
Algorithm Hash digest
SHA256 e2afc1083b28bcd30795ee7532a4d2134c86ed8e1749be61afb7fa5c4dc6dbef
MD5 6f7c6b0f7ff9ddc7f53c7f8021c31924
BLAKE2b-256 7b143bb2fe857674f931974b4c0ec55436ef65b93d946a116c2d80d0ca089fa1

See more details on using hashes here.

Supported by

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