Skip to content

A lightweight, Python-based email client designed to simplify the process of composing and sending emails programmatically.

Notifications You must be signed in to change notification settings

olivierbenard/email-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

email-client

A lightweight, Python-based email client designed to simplify the process of composing and sending emails programmatically.

Configuration

To configure the sending of automatic emails:

  1. Go to your Google Account's Security Page.
  2. Ensure that the 2-Step Verification is turned on.
  3. Go to the App Passwords page.
  4. Create an App (or select an existing one).
  5. 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"

Usage

Send an email without content

client = EmailClient()

client.send_email(
    subject="Text Only Email",
    sender="[email protected]",
    recipients=["[email protected]"],
)

Send an email with only a text body (html_body omitted)

client = EmailClient()

client.send_email(
    subject="Text Only Email",
    sender="[email protected]",
    recipients=["[email protected]"],
    text_body="Napoléon",
)

Send an email with only an HTML body (text_body omitted)

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>",
)

Send an email with both text and HTML

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>",
)

Send an email with an inline image (CID-based)L

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"},
)

About

A lightweight, Python-based email client designed to simplify the process of composing and sending emails programmatically.

Resources

Stars

Watchers

Forks

Packages

No packages published