make a program that sends a monthly email with utilities information in python

To send a monthly email with utilities information, you can use Python's built-in smtplib module to send an email using Simple Mail Transfer Protocol (SMTP). You will also need to use the email module to create and format the message to be sent.

Here's an example program that sends a monthly email with the utilities information:

main.py
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from datetime import datetime
import os

# set up email parameters
to_address = '<recipient email address>'
from_address = '<sender email address>'
password = '<sender email password>'
subject = 'Monthly Utilities Report'

msg = MIMEMultipart()
msg['From'] = from_address
msg['To'] = to_address
msg['Subject'] = subject

# get utilities information
# replace this with your own function to get the utilities information
utilities_info = '<insert utilities information here>'
text = MIMEText(utilities_info)
msg.attach(text)

# send the email
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(from_address, password)
server.sendmail(from_address, to_address, msg.as_string())
server.quit()

# print a message indicating that the email has been sent
now = datetime.now()
print("Monthly utilities report sent on {}/{}/{}".format(now.month, now.day, now.year))
982 chars
34 lines

This program sends an email to a recipient with the utilities information using Gmail's SMTP server on port 587. You'll need to replace the placeholders for to_address, from_address, and password with your own Gmail email address and password. You can modify the subject and utilities_info variables to customize the message to be sent.

To automate the program to run once a month, you can set up a cron job on a Unix system or a scheduled task on a Windows system to run the program on the first day of each month.

related categories

gistlibby LogSnag