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

API's

  API's Types of API's REST API - Representational State Transfer is a commonly used API category that isn’t dependent on a specific protocol. It’s considered a relatively user-friendly API to work with and many developers are experienced in this technology. It’s an architecture style of communicating interfaces. SOAP API - Simple Object Access Protocol is an API that connects different platforms together through HTTP and XML. Its relatively older than other API implementations, but it provides more security as it follows strict protocols. It’s a protocol for communication between applications. ASP.NET API - Specific form of REST API developed around .NET technology. REST vs SOAP Both have some similarities for instance they both support SSL/TLS for secure and encrypted communications, also they both use HTTP to exchange information. When deciding which API to use you must take in many factors into consideration like, security, ACID compliance, and overall application design. F...
  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...