Skip to main content

python-simple-email-sender

Project description

Python Simple Email Sender

A lightweight Python library for sending emails with attachments via SMTP.


Features

  • Send emails using SMTP protocol
  • Support for SSL encryption
  • Add attachments to emails
  • Environment variable-based configuration
  • Simple logging integration

Installation

pip install python-simple-email-sender

Usage

Basic Setup

First, set up your email credentials as environment variables:

export EMAIL_ADDRESS="your.email@gmail.com"
export EMAIL_PASSWORD="your-app-password-or-email-password"

Note: For Gmail accounts, you may need to use an App Password instead of your regular password, especially if you have 2-factor authentication enabled. https://myaccount.google.com/apppasswords


Simple Example

from python_simple_email_sender import EmailSender

# Create an instance with default settings (Gmail SMTP)
sender = EmailSender()

# Send a simple email
sender.send_email(
    to_email=["recipient@example.com"],
    subject="Hello from Python",
    message="This is a test email sent using Python Simple Email Sender."
)

Custom SMTP Server

# For a different email provider
sender = EmailSender(
    server_name="smtp.yourprovider.com",
    server_port=587  # Use the appropriate port for your provider
)

Sending with Attachments

sender.send_email(
    to_email=["recipient@example.com", "another@example.com"],
    subject="Report Attached",
    message="Please find the attached report.",
    attachment_file="path/to/your/file.pdf"
)

Adding Multiple Attachments

sender = EmailSender()

# Create the email
sender.msg = MIMEMultipart()
sender.msg['From'] = sender.email_address
sender.msg['To'] = 'recipient@example.com'
sender.msg['Subject'] = 'Multiple Attachments'

# Add message body
text = MIMEText("Here are the files you requested.")
sender.msg.attach(text)

# Add multiple attachments
sender.add_attachment("document.pdf", subtype="pdf")
sender.add_attachment("data.csv", subtype="csv")
sender.add_attachment("image.png", subtype="png")

# Send the email
with smtplib.SMTP_SSL(sender.server_name, sender.server_port) as smtp_server:
    smtp_server.login(sender.email_address, sender.email_password)
    smtp_server.sendmail(
        from_addr=sender.email_address,
        to_addrs=['recipient@example.com'],
        msg=sender.msg.as_string()
    )

🤝 Contributing

If you have a helpful tool, pattern, or improvement to suggest: Fork the repo
Create a new branch
Submit a pull request
I welcome additions that promote clean, productive, and maintainable development.


🙏 Thanks

Thanks for exploring this repository!
Happy coding!

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

python_simple_email_sender-1.0.7.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_simple_email_sender-1.0.7-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file python_simple_email_sender-1.0.7.tar.gz.

File metadata

File hashes

Hashes for python_simple_email_sender-1.0.7.tar.gz
Algorithm Hash digest
SHA256 2d4648679f3f21a2c970b060df0a812651735ff841eb4c0cc6944450beed4216
MD5 e76fb173b7d5a1a6754905f3551f66f3
BLAKE2b-256 e4b7740cfe27fc19ae7b1fce275c1e3ea40061b290bd33d642c976171c8b8804

See more details on using hashes here.

File details

Details for the file python_simple_email_sender-1.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for python_simple_email_sender-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 98f37e89d88fdd28406f76f92bacc10a5647fa76f8b64e9ee3ebf1cbbf7e61ad
MD5 9db4cf8df94c03b5683ee26895981f5b
BLAKE2b-256 787e56ebc4ac68ec3a61460bb0394a69163bbc92c45572872ef57d12333d65e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page