A lightweight Python library for sending emails with minimal setup
Project description
smtpmailmime
smtpmailmime is a lightweight Python library for sending emails with minimal setup. It automatically detects your email provider's SMTP settings so you don't have to configure them manually.
Installation
pip install smtpmailmime
Dependencies:
requests— fetches provider SMTP config automaticallyemail-validator— validates email addresses before sending
Quick Start
from smtpmailmime import EasyMail
email = EasyMail()
email.username = "you@gmail.com"
email.password = "your_password"
email.sent = {
"To": "recipient@example.com",
"Subject": "Hello!",
"Body": "This is the email body."
}
That's it. smtpmailmime will auto-detect the SMTP server for your provider and send the email.
Email Fields
| Field | Required | Description |
|---|---|---|
To |
Yes | Recipient email address(es). Separate multiple with commas. |
Cc |
No | Carbon copy recipient(s). Separate multiple with commas. |
Bcc |
No | Blind carbon copy recipient(s). Not visible to other recipients. |
Subject |
No | Email subject line. Defaults to "No subject" if omitted. |
Body |
No | Email body text. |
Body_type |
No | Set to "html" to send an HTML email. Defaults to "plain". |
Attachment |
No | File path(s) to attach. Separate multiple paths with commas. |
Examples
Sending to multiple recipients
email.sent = {
"To": "alice@example.com, bob@example.com",
"Subject": "Team Update",
"Body": "Here is the latest update."
}
CC and BCC
email.sent = {
"To": "alice@example.com",
"Cc": "manager@example.com",
"Bcc": "archive@example.com",
"Subject": "Project Report",
"Body": "Please find the report attached."
}
HTML email
email.sent = {
"To": "recipient@example.com",
"Subject": "HTML Email",
"Body": "<h1>Hello!</h1><p>This is an <b>HTML</b> email.</p>",
"Body_type": "html"
}
Sending attachments
email.sent = {
"To": "recipient@example.com",
"Subject": "Files attached",
"Body": "See attached files.",
"Attachment": "report.pdf"
}
Sending multiple attachments
email.sent = {
"To": "recipient@example.com",
"Subject": "Multiple Files",
"Body": "See the attached files.",
"Attachment": "report.pdf, photo.png, data.csv"
}
Provider Auto-Configuration
smtpmailmime uses Thunderbird's autoconfig service to look up SMTP settings based on your email domain. This means it works out of the box for most major providers (Gmail, Outlook, Yahoo, iCloud, etc.) without any manual setup.
Manual SMTP Configuration
If your provider is not supported or auto-config fails, you can override the settings manually:
email.username = "you@yourdomain.com"
email.password = "your_password"
email._config = {
"smtp": {
"server": "smtp.yourdomain.com",
"port": "587"
}
}
email.sent = {
"To": "recipient@example.com",
"Subject": "Manual config test",
"Body": "Sent using manual SMTP config."
}
Common Errors
| Error | Cause |
|---|---|
Missing email address |
username was not set |
Missing email password |
password was not set |
Unsupported email provider |
Auto-config could not find SMTP settings for your domain |
Missing recipient email address |
To field was not provided |
Invalid recipient email address |
One of the addresses in To, Cc, or Bcc is malformed |
Invalid email credentials |
Wrong username or password (SMTP auth failed) |
FileNotFoundError |
An attachment path does not exist |
Notes
- Emails are sent over SMTP with STARTTLS encryption (port 587).
- For Gmail, you may need to use an App Password if 2-factor authentication is enabled.
- BCC recipients are included in delivery but their addresses are not visible to
ToorCcrecipients.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smtpmailmime-0.1.3.tar.gz.
File metadata
- Download URL: smtpmailmime-0.1.3.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bafb3ecf5bf8f7443752d7be617926710bb8d399a766e77d32349013abf38ebd
|
|
| MD5 |
37b10c1f945281ffdb3f43082af52153
|
|
| BLAKE2b-256 |
80e7abf5b4a54c4801e1af109971d1f5d59cd5a60a2262813971befc44d75343
|
File details
Details for the file smtpmailmime-0.1.3-py3-none-any.whl.
File metadata
- Download URL: smtpmailmime-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4d7d064f3eaff8ff2562f0c7e6e11b0e9d62cda03d07b041a7df6d06a800500
|
|
| MD5 |
87d682e6e7242466cd8bb877841bda44
|
|
| BLAKE2b-256 |
84a1e9262c5722ab76d7a0fb10d0f975f8f6ecdb65a40a81aac02a48b6482f12
|