Docs
Docs
Usman Khan
Fahad Abdullah
Asma Zubair
Mehak Zahra
Iqra Najaf
AUTOMATIC MAILING
using
PYTHON
Project submitted to:
Ms. Akkasha Cheema
1
CONTENTS
1. Overview. .......................................................................................................... 2
2. How to use this project. .................................................................................... 2
3. Configuration .................................................................................................... 3
4. How the code is working (line by line). .............................................................. 3
4.1. Libraries ..................................................................................................... 3
4.2. Opening file. ............................................................................................... 4
4.3. Extracting data in list from columns. .......................................................... 4
4.4. Starting a server. ........................................................................................ 5
4.5. The sender credentials. .............................................................................. 5
4.6. Establishing connection and login. ............................................................. 6
4.7. Creating a body of mail. .............................................................................. 6
4.8. Finally, sending mail. .................................................................................. 6
4.9. For loop: ..................................................................................................... 7
2
1. Overview.
In summary, the provided Python script utilizes the pandas library to read
student information from an Excel file and the smtplib library to send
personalized result emails to each student. The script extracts email addresses,
student names, and scores in various subjects from the Excel data, constructs
individualized email content, and sends messages via Gmail's SMTP server.
The process involves initializing necessary email parameters, establishing a
secure connection using SSL, and iteratively sending emails to each student.
While the script successfully fulfills its purpose of automating result notifications,
it's crucial to address potential security concerns, particularly in handling email
credentials, for deployment in more secure and production-oriented scenarios.
Update the excel_file_path variable with the correct path to your Excel file
show in image below.
Save the changes to the script, run the script and you will sew the step-
by-step progress of emails being sent. Log in to the email account specified in
the script (email_from) to confirm that the result emails have been sent
successfully.
3. Configuration
The default server protocol to send the emails is “smtp.gmail.com” means
that the sender mail must be with the domain of “@gmail.com”. In case you
want to send emails by the domains from any other i.e. “@outlook.com” or
“@hotmail.com” you must add the server protocol accordingly.
smtplib imports the library, allowing you to use its functionality for
sending emails programmatically.
This snippet of code extracts data from columns in a list for each variable.
After running this code we will have the separate lists of email, names and
5
marks of subjects. This can then be used for further analysis, processing, or
other tasks in our Python code.
This line initializes a variable smtp_port with the value 587. 587 is the
standard port number for secure SMTP communication using the STARTTLS
encryption protocol. It's commonly used for secure email transmission.
This snippet is creating a body for the email that is going to be send. It is
getting data from excel sheet provided before saving a proper message in a
variable named as “msg”.
This line essentially initiates the process of sending an email from the
specified sender to the specified recipient using the connected SMTP server
7
(nerd_server). The content and structure of the email are defined by the msg
variable, which includes the subject and body of the email.
It looks like you are using the zip function to iterate over multiple lists
(email_list, name, eng, urd, math, prog, CSkills) simultaneously. The provided
code is using a for loop to iterate over these lists in parallel, and for each
iteration, it is assigning values from these lists to the corresponding variables
(person_email, names, english, urdu, math, progg, cskills). This is often used
when you have related data stored in separate lists and you want to process or
operate on them together.