-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f42674c
commit 0a678c9
Showing
10 changed files
with
313 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Harold Edsel Cabaluna | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,100 @@ | ||
# EmailSender | ||
# EmailSender Python Script | ||
|
||
**Author:** Harold Edsel F. Cabaluna | ||
|
||
The *EmailSender* Python script is a tool designed to simplify the process of sending emails using Python. This script leverages the power of Python's `smtplib` library to send emails programmatically, making it useful for various applications such as automating notifications, sending reports, or communicating with users. | ||
|
||
## Features | ||
|
||
- Send emails to one or more recipients. | ||
- Support for plain text and HTML email content. | ||
- Attachment functionality for sending files along with emails. | ||
|
||
## Prerequisites | ||
|
||
Before using the EmailSender script, ensure you have the following prerequisites: | ||
|
||
- Python 3.x installed on your system. | ||
- A valid email account from which you want to send emails. | ||
- Internet connectivity to establish a connection with the email server. | ||
|
||
## Installation | ||
|
||
1. Clone or download the repository to your local machine. git clone https://github.com/your_username/EmailSender.git | ||
|
||
2. Navigate to the project directory: | ||
```cd EmailSender``` | ||
|
||
3. Install the required dependencies: | ||
```pip install -r requirements.txt``` | ||
|
||
## Usage | ||
|
||
1. Open the `config.py` file and provide your email account details: | ||
|
||
```python | ||
# Email Account Configuration | ||
EMAIL_ADDRESS = "[email protected]" | ||
EMAIL_PASSWORD = "your_email_password" | ||
``` | ||
|
||
1. Customize the main.py script to set the recipient's email address, subject, message, and attachments (if needed). | ||
|
||
2. Run the script: | ||
```python EmailSender/sender.py``` | ||
|
||
3. The script will establish a connection to the email server and send the email with the specified content and attachments. | ||
|
||
## Example | ||
|
||
```python | ||
from EmailSenderVaryTest import config | ||
|
||
email_sender = config.EMAIL_ADDRESS | ||
|
||
recipient = "[email protected]" | ||
|
||
subject = "Hello from EmailSenderVaryTest!" | ||
message = "This is a test email sent using the EmailSenderVaryTest script." | ||
|
||
attachment_path = "path/to/attachment.pdf" | ||
email_sender.attach_file(attachment_path) | ||
|
||
email_sender.send_email(recipient, subject, message) | ||
``` | ||
|
||
## SMTP Setup | ||
``` | ||
Generate an Application-Specific Password: | ||
1. Go to your Google Account settings: https://myaccount.google.com/ | ||
2. In the "Security" section, find the "Signing in to Google" option. | ||
3. Click on "App passwords." | ||
4. Select "Mail" and "Other (Custom name)" from the dropdowns. | ||
5. Enter a custom name for your app, like "EmailSender." | ||
6. Click the "Generate" button. | ||
7. Google will provide you with a generated password. Copy this password.**** | ||
``` | ||
|
||
## Use the Application-Specific Password in your Code | ||
In config.py script, replace the EMAIL_PASSWORD variable | ||
with the generated application-specific password you obtained from Google: | ||
```python | ||
EMAIL_PASSWORD = 'your_generated_app_password' | ||
``` | ||
|
||
## Contributions | ||
Contributions to the EmailSender Python script are welcome! If you find any issues or want to enhance its features, feel free to create a pull request. | ||
|
||
## License | ||
This project is licensed under the MIT License - see the LICENSE.txt file for details. | ||
|
||
Feel free to reach out to me at [email protected] for any questions or suggestions! Your feedback is greatly appreciated. | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
EMAIL_ADDRESS = "[email protected]" | ||
EMAIL_PASSWORD = "mmzvetgylnfqzjsp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import smtplib | ||
import re | ||
import os | ||
|
||
from email.mime.multipart import MIMEMultipart | ||
from email.mime.text import MIMEText | ||
from email.mime.image import MIMEImage | ||
from email.mime.application import MIMEApplication | ||
from config import EMAIL_ADDRESS, EMAIL_PASSWORD | ||
|
||
|
||
def getFromConfig(): | ||
sender_email = EMAIL_ADDRESS | ||
sender_password = EMAIL_PASSWORD | ||
|
||
receiver_email = str(input("Receiver Email: ")) | ||
subject = str(input("Subject: ")) | ||
message = str(input("Message: ")) | ||
|
||
return sender_email, sender_password, receiver_email, subject, message | ||
|
||
|
||
def MimeObject(sender_email, receiver_email, subject, message): | ||
msg = MIMEMultipart() | ||
msg['From'] = sender_email | ||
msg['To'] = receiver_email | ||
msg['Subject'] = subject | ||
msg.attach(MIMEText(message, 'plain')) | ||
|
||
return msg | ||
|
||
|
||
def SMPTSending(sender, receiver_email, message): | ||
smtp_server = 'smtp.gmail.com' | ||
smtp_port = 587 | ||
smtp_username = EMAIL_ADDRESS | ||
smtp_password = EMAIL_PASSWORD | ||
|
||
server = smtplib.SMTP(smtp_server, smtp_port) | ||
server.starttls() | ||
|
||
try: | ||
server.login(smtp_username, smtp_password) | ||
except smtplib.SMTPAuthenticationError as e: | ||
error_message = e.smtp_error.decode() if hasattr(e, 'smtp_error') else str(e) | ||
|
||
if "BadCredentials" in error_message: | ||
print("SMTP Authentication Error: The username or password is not accepted.") | ||
else: | ||
print("SMTP Authentication Error:", error_message) | ||
except Exception as e: | ||
print("An error occurred:", e) | ||
|
||
gmail_email_pattern = r'^[a-zA-Z0-9._%+-]+@gmail\.com$' | ||
if re.match(gmail_email_pattern, receiver_email): | ||
server.sendmail(sender, receiver_email, message.as_string()) | ||
else: | ||
print("Invalid Receiver Email.") | ||
|
||
server.quit() | ||
|
||
|
||
if __name__ == "__main__": | ||
os.system('cls' if os.name == 'nt' else 'clear') | ||
|
||
email = "" | ||
password = "" | ||
receiver = "" | ||
subj = "" | ||
msg = "" | ||
|
||
# Email Configuration | ||
gmail_email_pattern = r'^[a-zA-Z0-9._%+-]+@gmail\.com$' | ||
if re.match(gmail_email_pattern, EMAIL_ADDRESS): | ||
email, password, receiver, subj, msg = getFromConfig() | ||
else: | ||
print("Invalid Sender Email.") | ||
|
||
# Object for the Email | ||
mimeMSG = MimeObject(email, receiver, subj, msg) | ||
|
||
# STAGE 1: Connect to the SMTP server | ||
# STAGE 2: Start the server connection | ||
# STAGE 3: Log in to your email account | ||
# STAGE 4: Send the email | ||
# STAGE 5: Quit the server | ||
SMPTSending(email, receiver, mimeMSG) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
EMAIL_ADDRESS = "[email protected]" | ||
EMAIL_PASSWORD = "mmzvetgylnfqzjsp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import smtplib | ||
import re | ||
import os | ||
|
||
from email.mime.multipart import MIMEMultipart | ||
from email.mime.text import MIMEText | ||
from email.mime.image import MIMEImage | ||
from email.mime.application import MIMEApplication | ||
from config import EMAIL_ADDRESS, EMAIL_PASSWORD | ||
|
||
|
||
def getFromConfig(): | ||
sender_email = EMAIL_ADDRESS | ||
sender_password = EMAIL_PASSWORD | ||
|
||
receiver_email = str(input("Receiver Email: ")) | ||
subject = str(input("Subject: ")) | ||
message = str(input("Message: ")) | ||
|
||
return sender_email, sender_password, receiver_email, subject, message | ||
|
||
|
||
def MimeObject(sender_email, receiver_email, subject, message): | ||
msg = MIMEMultipart() | ||
msg['From'] = sender_email | ||
msg['To'] = receiver_email | ||
msg['Subject'] = subject | ||
msg.attach(MIMEText(message, 'plain')) | ||
|
||
return msg | ||
|
||
|
||
def SMPTSending(sender, receiver_email, message): | ||
smtp_server = 'smtp.gmail.com' | ||
smtp_port = 587 | ||
smtp_username = EMAIL_ADDRESS | ||
smtp_password = EMAIL_PASSWORD | ||
|
||
server = smtplib.SMTP(smtp_server, smtp_port) | ||
server.starttls() | ||
|
||
try: | ||
server.login(smtp_username, smtp_password) | ||
except smtplib.SMTPAuthenticationError as e: | ||
error_message = e.smtp_error.decode() if hasattr(e, 'smtp_error') else str(e) | ||
|
||
if "BadCredentials" in error_message: | ||
print("SMTP Authentication Error: The username or password is not accepted.") | ||
else: | ||
print("SMTP Authentication Error:", error_message) | ||
except Exception as e: | ||
print("An error occurred:", e) | ||
|
||
gmail_email_pattern = r'^[a-zA-Z0-9._%+-]+@gmail\.com$' | ||
if re.match(gmail_email_pattern, receiver_email): | ||
server.sendmail(sender, receiver_email, message.as_string()) | ||
else: | ||
print("Invalid Receiver Email.") | ||
|
||
server.quit() | ||
|
||
|
||
if __name__ == "__main__": | ||
os.system('cls' if os.name == 'nt' else 'clear') | ||
|
||
email = "" | ||
password = "" | ||
receiver = "" | ||
subj = "" | ||
msg = "" | ||
|
||
# Email Configuration | ||
gmail_email_pattern = r'^[a-zA-Z0-9._%+-]+@gmail\.com$' | ||
if re.match(gmail_email_pattern, EMAIL_ADDRESS): | ||
email, password, receiver, subj, msg = getFromConfig() | ||
else: | ||
print("Invalid Sender Email.") | ||
|
||
# Object for the Email | ||
mimeMSG = MimeObject(email, receiver, subj, msg) | ||
|
||
# STAGE 1: Connect to the SMTP server | ||
# STAGE 2: Start the server connection | ||
# STAGE 3: Log in to your email account | ||
# STAGE 4: Send the email | ||
# STAGE 5: Quit the server | ||
SMPTSending(email, receiver, mimeMSG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
setuptools~=65.5.1 | ||
emailsender~=1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name='EmailSenderVaryTest', | ||
version='1.0.0', | ||
description='A python script program to send emails using SMTP', | ||
author='Harold Edsel F. Cabaluna', | ||
author_email='[email protected]', | ||
license='MIT', | ||
keywords='email sender smtp', | ||
packages=['EmailSenderVaryTest'], | ||
) |