Skip to main content

py-mail

Build status

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:

  1. get_mail_text_from_last_few
  2. 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:

Metadata

Release files for py-mail 0.0.4

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

Source distribution (sdist)

Source distribution for py-mail 0.0.4
File Size Uploaded
py-mail-0.0.4.tar.gz 6.1 kB Details

Release files / py-mail-0.0.4.tar.gz

Download URL py-mail-0.0.4.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2bc833214bf1840d4117db4d0b1ace4719b6b93e1a14644a564426dec61372ae
BLAKE2b-256 checksum
How to use checksums
93861e2c27631ecde650ce6ce793d92bc2e4e0a6a31884def150aa4cc0027697
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.4 This release

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

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