0% found this document useful (0 votes)
19 views8 pages

Docs

The Python script reads student data from an Excel file, extracts email addresses, names, and subject scores. It constructs personalized emails, connects to Gmail's SMTP server using TLS, and sends emails to each student by iterating through lists of their information. While it automates result notifications, security best practices like handling credentials securely need to be addressed for production.

Uploaded by

USMAN KHAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views8 pages

Docs

The Python script reads student data from an Excel file, extracts email addresses, names, and subject scores. It constructs personalized emails, connects to Gmail's SMTP server using TLS, and sends emails to each student by iterating through lists of their information. While it automates result notifications, security best practices like handling credentials securely need to be addressed for production.

Uploaded by

USMAN KHAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Submitted by:

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.

2. How to use this project.


Make sure your student data is organized in an Excel file with columns
like "Email," "Student_name," "English," "Urdu," "Maths," "Skills," and
"Programming". Save the Excel file in a location accessible to the script.

Update the excel_file_path variable with the correct path to your Excel file
show in image below.

Replace the placeholder values for smtp_server, email_from, and


password.
3

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.

4. How the code is working (line by line).


4.1. Libraries

• pandas (import pandas as pd):

Pandas is a popular data manipulation and analysis library in


Python. After this import, you can use pd to reference the pandas
library in your code.

• smtplib (import smtplib):

smtplib is a library that provides an interface for sending


emails using the Simple Mail Transfer Protocol (SMTP). import
4

smtplib imports the library, allowing you to use its functionality for
sending emails programmatically.

• ssl (import ssl):


ssl is the Secure Sockets Layer protocol, a standard security
technology for establishing encrypted links between a web server
and a browser.

4.2. Opening file.

This variable is assigned a string containing the file path of an Excel


file named "students_demo.xlsx". The file path is an absolute path pointing
to the location of the Excel file on the user's desktop.

pd.read_excel() is a function provided by the pandas library to read


data from an Excel file into a Data Frame. The argument passed to
pd.read_excel() is the file path (excel_file_path) indicating the location of the
Excel file to be read. The result of this operation is a DataFrame (df in this
case) that contains the data from the Excel file.

4.3. Extracting data in list from columns.

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.

4.4. Starting a server.

• SMTP port = 587:

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.

• SMTP server = "smtp.gmail.com":

This line initializes a variable smtp_server with the string "smtp.gmail.com".


"smtp.gmail.com" is the SMTP server address for Gmail. It's the server through
which emails will be sent.

4.5. The sender credentials.

“email_from” is set to the email address "[email protected]," and


“password” is set to the corresponding password. These are likely the
credentials for the Gmail account from which you intend to send emails. Replace
"[email protected]" with the actual email address where you want to send
the email.
6

4.6. Establishing connection and login.

The combined effect of these lines is to establish a secure connection to


the Gmail SMTP server using the TLS protocol and log in with the specified
email address and password. After this setup, you can use the nerd_server
instance to send emails through the Gmail SMTP server.

4.7. Creating a body of mail.

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”.

4.8. Finally, sending mail.

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.

4.9. For loop:

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.

You might also like