diff --git a/AUTOMATION/Email Automation/ReadMe.MD b/AUTOMATION/Email Automation/ReadMe.MD new file mode 100644 index 00000000..8de7214b --- /dev/null +++ b/AUTOMATION/Email Automation/ReadMe.MD @@ -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. \ No newline at end of file diff --git a/AUTOMATION/Email Automation/automatedSending.py b/AUTOMATION/Email Automation/automatedSending.py new file mode 100644 index 00000000..9145a79d --- /dev/null +++ b/AUTOMATION/Email Automation/automatedSending.py @@ -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 = ''' + +
+{}
+This is a bold example.
+This is an italic example.
+ + + '''.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 = 'varda.quraishi@globewyze.com' +recipient_email = 'vardaquraishi@gmail.com' +subject = 'Hello from Python Email Script' +message = 'This is an automated email sent using Python.' + +send_email(sender_email, recipient_email, subject, message)