A lightweight, Python-based email client designed to simplify the process of composing and sending emails programmatically.
To configure the sending of automatic emails:
- Go to your Google Account's Security Page.
- Ensure that the 2-Step Verification is turned on.
- Go to the App Passwords page.
- Create an App (or select an existing one).
- You will get a 16-characters password. Copy this password - it's your app password.
Create or edit the .env
environment variables file:
SMTP_HOST = "smtp.example.com"
SMTP_PORT = "587"
SMTP_USERNAME = "<username>"
SMTP_PASSWORD = "<password>"
SMTP_USE_TLS = "true"
client = EmailClient()
client.send_email(
subject="Text Only Email",
sender="[email protected]",
recipients=["[email protected]"],
)
client = EmailClient()
client.send_email(
subject="Text Only Email",
sender="[email protected]",
recipients=["[email protected]"],
text_body="Napoléon",
)
client_email = EmailClient()
client_email.send_email(
subject="HTML Only Email",
sender="[email protected]",
recipients=["[email protected]"],
html_body="<h2>Only HTML Content</h2><p>This email has no plain text body.</p>",
)
client_email = EmailClient()
client_email.send_email(
subject="Text & HTML Email",
sender="[email protected]",
recipients=["[email protected]"],
text_body="This is the plain text version.",
html_body="<h2>This is the HTML version</h2><p>It has formatting.</p>",
)
client_email = EmailClient()
client_email.send_email(
subject="Email with Inline Image",
sender="[email protected]",
recipients=["[email protected]"],
html_body='<h2>Image Example</h2><img src="cid:example_image">',
inline_images={"example_image": "path/to/image.png"},
)