Provides data from the gmail mailbox in a human readable type
Project description
py-mail
The project will provide the ability to receive data from the gmail mailbox in human readable type. For these purposes, there are two main functions:
get_mail_text_from_last_few
get_mail_text_by_id
1. get_mail_text_from_last_few
This function looks at each letter in the mailbox and return the letter for the specified user.
"How is this possible?" - get_mail_text_from_last_few
requires a unique email address. For example:
some.address+9014@gmail.com
some.address+currnet_date()@gmail.com
some.address+datetime.now()@gmail.com
Arguments:
expected_email
: expected email address who received the message ~some.address+9014@gmail.com
flag
: additional filter for gmail messages ~flag='Subject "Welcome to Gmail!"'
timeout
: time to exit the loop in sec. (end fetching data) ~timeout=60
last_few
: number of recent emails among which will be searched by expected_email ~last_few=5
label
: target label. Will be used this label if then different from MailClient ~label='inbox'
from datetime import datetime
import pytest
from py_mail import MailClient
@pytest.fixture
def mail_client():
mail_client = MailClient(email_address='some.address@gmail.com', password='AmazingPass', label='inbox')
yield mail_client
mail_client.logout()
def get_email_by_idimap_client(mail_client):
expected_email = f'some.address+{datetime.now()}@gmail.com'
mail = mail_client.get_mail_text_from_last_few(expected_email=expected_email, last_few=10, timeout=60)
return mail # or you can search some specific data from letter via regex
2. get_mail_text_by_id
This function takes the letter by index (the last one is by default) and returns its content (text). The downside is that you can get the wrong email: because of problems with long delivery or because of the large number of incoming letters
Arguments:
label
- additional filter for gmail messages ~flag='Subject "Welcome to Gmail!"'
flag
- target label. Will be used this label if then different from MailClient ~label='inbox'
index
- index of required mail (bigger is newer) ~index=-1
import pytest
from py_mail import MailClient
@pytest.fixture
def mail_client():
mail_client = MailClient(email_address='some.address@gmail.com', password='AmazingPass', label='inbox')
yield mail_client
mail_client.logout()
def get_email_by_id(mail_client):
mail = mail_client.get_mail_text_by_id(label='other inbox', flag='subject "Confirm your device"')
return mail # or you can search some specific data from letter via regex
Useful Links:
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
File details
Details for the file py-mail-0.0.4.tar.gz
.
File metadata
- Download URL: py-mail-0.0.4.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bc833214bf1840d4117db4d0b1ace4719b6b93e1a14644a564426dec61372ae |
|
MD5 | 5bcf4411198e8a37100229771c82d72b |
|
BLAKE2b-256 | 93861e2c27631ecde650ce6ce793d92bc2e4e0a6a31884def150aa4cc0027697 |