Skip to content

Repository shows the demonstration of team email reports deliverables by python automation and task scheduler. As a part of organizational process, we need to pull data from client source and get reports activities to team by mails on daily basis. This is productive, time reduction and error free process by automating whole things as per the req…

License

Notifications You must be signed in to change notification settings

kunalk3/Automation_team_email_reports

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Daily email report delivarables (python email automation with scheduler)

Usecase - User wants to pull data from client source (Web, email, servers, shared locations, etc) on daily basis and need to ETL process, information retrivals and generate report. This report is of any type (Ex. Html file, Excel file, etc) and for further client activities, we need to notify by mail to team members/ HODs on daily basis as per the reqiorements.

1

- Google has announced that it’s disabling the Less Secure Apps feature on some Google accounts from May 30th, 2022. If you’re using Gmail SMTP details with our Other SMTP mailer, you may have difficulty sending emails when this feature is disabled. What next??

Windows Visual Studio Code Jupyter Pycharm Colab Spyder Streamlit

LinkedIn Badge Github Badge Gmail Badge Facebook Badge Instagram Badge


🧊 Overview:

  • With growing awareness of security, it’s highly recommended to have 2-Step Verification set up in your Google account, if not already. However, with 2-Step Verification enabled, you’ll realise that:
    • Less secure app access” option is no longer visible in Google
    • Programmatic login with your Google password only satisfies one of the 2-Step Verification

Essentially, you are blocked from accessing your Google Account programmatically now. So, how do we proceed from here now?


πŸ’‘ Demo

Automate.reprot.via.mail.demo.mp4

πŸ”§ Installation

Structure

A) Generating App Passwords from Google

B) Programming: Setup script and send email in Python

C) Adding script in Task Scheduler for automation


A) Generating App Passwords from Google: First, I recommend setting up a new Google account as a development environment for this tutorial instead of direct implementation in your desired (production/personal) Google Gmail account.

  • i. Set up a Google account. Skip this if you are using an existing Gmail account, and skip to point 4 if the account has 2-Step Verification enabled.
  • ii) Once logged on to your Google account, navigate to Manage your Google Account -> Security -> Privacy Setting

2

  • iii) Setup 2-Step Verification by following the on-screen instructions. Once you have 2-Step Verification enabled, the App Passwords option should be visible.
  • iv) Under App Passwords, select Other (Custom name) from the Select app dropdown list.

3

  • v) Give it a name for your own identification. Click on GENERATE and a 16-character code (in the format of xxxx-xxxx-xxxx-xxxx) should be generated. This code is important for programatically access.

4

B) Programming: Setup script and send email in Python: We will be using the built-in module for sending emails via SMTP. SMTP is the protocol used for sending emails and routing emails between mail servers.

  • Create virtual environment python -m venv VIRTUAL_ENV_NAME and activate it .\VIRTUAL_ENV_NAME\Scripts\activate.

  • Install necessary library for this project from the file requirements.txt or manually install by pip.

    pip install -r requirements.txt
    

    To create project library requirements, use below command,

    pip freeze > requirements.txt
    
  • Store your own 16-character code (xxxx-xxxx-xxxx-xxxx) generated from Google in credentials JSON file into pass key without '-'. Also mentioned email person details To, CC, BCC as per below.

    {
      "from": "XYZ@gmail.com",
      "pass": "xxxxxxxxxxxxxxxx",
      "to": "ABC@gmail.com",
      "cc": ["ABC1@gmail.com", "ABC2@gmail.com"],
      "bcc": ["ABC3@gmail.com", "ABC4@gmail.com"]
    }
  • Configure input and output path with data as per requirements in code file.

    SOURCE_NODE = './sourceNode/'            # Input directory / data
    DESTINATION_NODE = './destinationNode/'  # Output directory / data
    
    # Email body
    text1 = 
    '''
    Hi Team,
    Good Morning, Please find below report.
    '''
    
    # Email configuration setup
    context = ssl.create_default_context()
    server = smtplib.SMTP_SSL('smtp.gmail.com', 465, context=context)
    server.login(sender_id, sender_pass)
  • Run app.py python file locally in machine. Once all set, check mails, windows notification and then we will move to automate the process by Schedulling job.

    python run app.py
    

    Once all set, check mails, windows notification and then we will move to automate the process by Scheduling job.

C) Adding script in Task Scheduler for automation: Here I have created video for this process automation on daily basis for a references (System: Windows 10).

  • Create task from Task Scheduler (Add name, description, machine settings)

  • Configure trigger settings on daily/ weekly/ specific day with time and repeatition for job.

  • Provide script path, script name and python path for python application.

    C:\Users...\Scripts\python.exe -> python cmd enabled

    C:\Users...\Scripts\pythonw.exe -> python cmd disabled

Automate.using.Task.Scheduler.mp4

πŸ”– Directory Structure

    .                                       # Root directory
    β”œβ”€β”€ sourceNode                          # Data source directory
    β”‚   └──us-500.csv                       # Data file - input
    β”œβ”€β”€ destinationNode                     # Data destination directory
    β”‚   └──output.html                      # Data file - output
    β”œβ”€β”€ app.py                              # Script file
    β”œβ”€β”€ credentials.json                    # Email credentials
    β”œβ”€β”€ requirements.txt                    # Project requirements library with versions
    β”œβ”€β”€ README.md                           # Project README file
    └── LICENSE                             # Project License file

πŸ“± Connect with me

You say freak, I say unique. Don't wait for an opportunity, create it.

Let’s connect, share the ideas and feel free to ping me...

kunalkolhe3 kunalkolhe3 kunal.kolhe.98 kunalkolhe333 kkunalkkolhe kunalkolhe333

About

Repository shows the demonstration of team email reports deliverables by python automation and task scheduler. As a part of organizational process, we need to pull data from client source and get reports activities to team by mails on daily basis. This is productive, time reduction and error free process by automating whole things as per the req…

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published