Skip to content

initial commit email automation #300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions AUTOMATION/Email Automation/ReadMe.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Automating email sending task

## Introduction
utilizing the `smtplib` library

`smtp_server` and `smtp_port`: Set these variables to the appropriate SMTP server and port of your email provider.

`sender_email`: Specify the email address from which you want to send the email.

`sender_password`: Provide the password or an app-specific password for the sender's email account.

`recipient_email`: Specify the recipient's email address.

`subject`: Set the subject line of the email.

`message`: Provide the content or body of the email.
55 changes: 55 additions & 0 deletions AUTOMATION/Email Automation/automatedSending.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

def send_email(sender_email, recipient_email, subject, message):
# SMTP server configuration
smtp_server = 'smtp.gmail.com'
smtp_port = 587

# Get the sender password from an environment variable
sender_password = os.environ.get('EMAIL_PASSWORD')

if not sender_password:
print("Error: Email password not set in environment variable.")
return

# Create the email message
email = MIMEMultipart()
email['From'] = sender_email
email['To'] = recipient_email
email['Subject'] = subject

# Create a MIMEText object with HTML content
html_content = '''
<html>
<body>
<h1>{}</h1>
<p>{}</p>
<p>This is a <strong>bold</strong> example.</p>
<p>This is an <em>italic</em> example.</p>
</body>
</html>
'''.format(subject, message)

email.attach(MIMEText(html_content, 'html'))

# Connect to the SMTP server
server = smtplib.SMTP(smtp_server, smtp_port)
server.starttls()
server.login(sender_email, sender_password)

# Send the email
server.sendmail(sender_email, recipient_email, email.as_string())

# Close the connection
server.quit()

# Example usage
sender_email = '[email protected]'
recipient_email = '[email protected]'
subject = 'Hello from Python Email Script'
message = 'This is an automated email sent using Python.'

send_email(sender_email, recipient_email, subject, message)