Email Automation
Work Automation - 2022
The Python script automates the process of sending Outlook emails based on specific flagged criteria from an input Excel file. It uses the pandas
library for handling Excel data, the openpyxl
library for reading Excel files, and the pywin32
library for interacting with Outlook.
- Import the required libraries:
pandas
,openpyxl
, andwin32com.client
. - Read the input Excel file using
pandas.read_excel()
, specifying theopenpyxl
engine to handle the file. This will load the Excel data into a pandas DataFrame. - Filter the DataFrame to extract rows that meet the flagged criteria. This can be done using boolean indexing or the
query()
method available in pandas. - For each row that meets the criteria, extract the necessary information, such as the recipient's email address, subject, and email body content.
- Establish a connection to Outlook by creating an instance of the
win32com.client.Dispatch("Outlook.Application")
object. - For each recipient, create a new mail item using the
CreateItem()
method of the Outlook application object, and populate the email fields (such asTo
,Subject
, andBody
) with the extracted information. - Send the email using the
Send()
method of the mail item. - Close the Outlook connection and provide a summary of the emails sent, if needed.
This Python script streamlines the process of sending personalized emails based on specific criteria from an input Excel file, making it an efficient solution for automated email notifications.