A simple, lightweight Python program to send and fetch emails using SMTP and IMAP.
- Send emails using SMTP
- Fetch emails using IMAP
- Support for HTML content
- Attachment handling
- Python 3.6+
- Clone this repository
git clone https://github.com/cipherodev/pymailer.git
- Enter pymailer directory
- Install dependencies:
pip install -r requirements.txt
from pymailer import PyMailer
mailer = PyMailer(
username='you@gmail.com',
password='abcd efgh ijkl mnop',
)
mailer.send(
to='someone@domain.com',
subject='Hello',
body='Hello, World!',
html='<h1>Hello, World!</h1>',
attachments=['/path/to/file.pdf', '/path/to/file.png'],
)
email = mailer.fetch()[0]
print(f'UID: {email["uid"]}')
print(f'FROM: {email["from"]}')
print(f'SUBJECT: {email["subject"]}')
print(f'BODY: {email["text"]}')
print(f'HTML: {email["html"]}')
print(f'ATTACHMENTS: {email["attachments"]}')Note: As of now you can only sign in with gmail
For the password use your google app password. To create one go to Google account page Navigate to "apps passwords" and create a new one named "pymailer". Use the password it gives you.
- Use App Passwords for Gmail instead of your account password
- Keep your credentials secure
MIT License