Send MIME messages via SMTP server and retrieve messages via POP3 and IMAP
Project description
A simple script to send MIME message via SMTP server and retrieve messages via POP3
Installation
pip install SMTPEmail
Install using Git
git clone https://github.com/Weizhang2017/SMTPEmail.git
cd SMTPEmail
python install setup.py
Usage
Sending email via SMTP
from SMTPEmail import SMTP
client = SMTP(
SMTP_server=<domain> or <IP_address>,
SMTP_account=<account_name>,
SMTP_password=<SMTP_password>
)
client.create_mime(
recipient_email_addr='Jane.Doe@jane.com',
sender_email_addr='John.Doe@john.com',
subject='subject',
sender_display_name='John Doe',
recipient_display_name='Jane Doe',
content_html='<p>hello world</p>',
content_text='hello world'
)
client.send_msg()
Add customized email header
custom_header = {'Sender': 'john@abc.com'}
client.create_mime(
recipient_email_addr='Jane.Doe@jane.com',
sender_email_addr='John.Doe@john.com',
subject='subject',
sender_display_name='John Doe',
recipient_display_name='Jane Doe',
content_html='<p>hello world</p>',
content_text='hello world',
custom_header=custom_header
)
Retrieve email via POP3
messages will be returned in byte object
from SMTPEmail import POP3
client = POP3(
POP3_server = <domain> or <IP_address>,
POP3_account = <account_name>,
POP3_password = <POP3_password>
)
msgs = client.retrieve_msg()
for msg in msgs:
print(msg)
>>>print(client.mailbox_size())
{'message count': 804, 'mailbox size': 18096539}
Retrieve email via IMAP
from SMTPEmail import IMAP
client = IMAP(
IMAP_server = <domain> or <IP_address>,
IMAP_account = <account_name>,
IMAP_password = <IMAP_password>
)
#you can select which mailbox to access and which email to retrieve by passing parameters 'mailbox_name' and 'msg_id'
for msg in client.retrieve_msg(mailbox_name='inbox', msg_id='1,3,5-8,11'):
print(msg)
#'mailbox_name' and 'msg_id' are optional, the user will be promted to input the two parameters if either is missing
>>>msgs = client.retrieve_msg()
0. "INBOX"
1. "Templates"
...
Please select a mailbox:1
message id: 1 2 3 4 5 6 ...
Please select mail ID to retrieve email(e.g. 1-5,6,7): 1,3-6
Additonal features:
- Specify variable
delete=Trueto delete the messages that have been retrieved, default value isFalse - Specify variable
msg_id='all'to retrieve all messages
Search emails via IMAP
Refer to RFC3501 for more search options
>>>for msg in client.retrieve_msg(mailbox_name='inbox', search_section='body', search_text='test_search'):
print(msg)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file SMTPEmail-0.4.2-py3-none-any.whl.
File metadata
- Download URL: SMTPEmail-0.4.2-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b4a5858626d354822113721fe5d37f4d449bea93b5664b9d7e20730282e41fb
|
|
| MD5 |
7ba7c7cb71979078410fae813087d81a
|
|
| BLAKE2b-256 |
728ecbc9f439f8d7ac763728c31667b6ec524fe5bf15dced9120735c79fb1a49
|