Skip to main content

Algorithms

 

Algorithms

Objective: Write a python script to automate the daily sending of email messages. The script should generate a daily message and send it via email.

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import schedule
import time

# Function to send email
def send_email(subject, body, to_email):
    # email credentials
    sender_email = "#for security reasons this will be hidden"
    sender_password = "#for security reasons this will be hidden"  

    # Create message
    message = MIMEMultipart()
    message["From"] = sender_email
    message["To"] = to_email
    message["Subject"] = subject
    message.attach(MIMEText(body, "plain"))

    # Connect to the SMTP server (Gmail in this case)
    with smtplib.SMTP("smtp.gmail.com", 587) as server:
        server.starttls()
        server.login(sender_email, sender_password)
        server.send_message(message)

# Function to generate daily report
def generate_d
aily_report
():
    report_content = "#personal message of choice"

    # Send the email
    send_email("Daily Report", report_content, "#for security reasons this will be
hidden")  

# Scheduling the script to run daily at a specific time
schedule.every().day.at("09:48").do(generate_daily_report)

# Run the script indefinitely
while True:
    schedule.run_pending()
    time.sleep(1)

I went and tested this out and here's the email that came through, for security and safety reasons I have removed and I've hidden any personal information.



This is the decomposition of this code:


Comments

Popular posts from this blog

Types of network adapters in virtual box

  Types of network adapters in VirtualBox In VirtualBox there’s multiple types of network adapters that can be used to configure virtual machines for different networking needs. Down below will give you a brief overview of each type. NAT (network address translation) The VM is placed behind a VirtualBox-managed router. This allows the VM to access the external network via the networks host’s IP, but the VM itself remains invisible to the outside. Its most suitable for simple internet access with minimal configuration NAT network This is like NAT, but it allows multiple VM’s to communicate with each other in the same NAT network all while sharing the host’s internet connection. Its commonly used when you want to simulate a small, isolated network of VM’s that can also access the internet. Bridged adapter This VM is connected directly to the physical network as if it is a separate device, it also receives its own IP address from the same network as the host. This is ide...

Legislation and Regulation

    Legislation and Regulation Investigatory powers act 2016 The Investigatory Powers Act 2016 is a UK law allowing authorities to collect and access large amounts of communications data, including internet history. It permits hacking devices and networks for investigations, mandates the storage of internet connection records for up to 12 months, and requires warrants for surveillance, overseen by a judge and a Secretary of State. It aims to enhance national security but has faced criticism for potential privacy violations due to its extensive surveillance powers. Freedom of information act 2000 - processes(responding/requesting) Requesting Information: ·           Individuals can ask public authorities for information in writing. ·           Specify details to help find the information. ·           Requests can be sent via email, let...
  Designing a SOHO network with DHCP Network requirements for the office Sales department – 4 computers Finance department – 3 computers Networking devices requirement: ·          1 router ·          2 switches (one for each department) ·          1 DHCP server Documentation I started by setting up the network topology and used the automatic connecting cable to connect all the devices together. Then I configured the server with IPv4 address and a subnet mask. to do this you have to press on the server and then go to desktop. Then I filled in all the parameters as seen below. Then I had to configure the DHCP server. To do this I clicked on the server > services > DHCP. Then I turned on the serves and configured the server as seen in this screenshot. For the next step I configured the router with the IPv4 address and subnet mask. To a...