September 29, 2022 at 3:18 PM
Found this script to send emails via a Python script and edited it a bit to be able to send multiple messages as opposed to just one by using a for loop at the end. Worked with just one, adding the for loop broke it:(
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from email.mime.text import MIMEText
MY_ADDRESS = ""
MY_PASSWORD = ""
RECIPIENT_ADDRESS = ""
HOST_ADDRESS = ""
HOST_PORT =
#connection to server
server = smtplib.SMTP(host=HOST_ADDRESS, port=HOST_PORT)
server.starttls()
server.login(MY_ADDRESS, MY_PASSWORD)
#create mime multipart object
message = MIMEMultipart()
#mime multipart object header
message['From'] = MY_ADDRESS
message['To'] = RECIPIENT_ADDRESS
message['Subject'] = "Automated Email with Attachment"
#mime text
textPart = MIMEText("Did it work?", 'plain')
#mime application
filename = "document.txt"
filePart = MIMEApplication(open(filename,"rb").read(),Name=filename)
filePart["Content-Disposition"] = 'attachment; filename="%s' % filename
#attach parts
message.attach(textPart)
message.attach(filePart)
#send message as many times as needed (this is what breaks it)
for i in range(5):
server.send_message(message)
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from email.mime.text import MIMEText
MY_ADDRESS = ""
MY_PASSWORD = ""
RECIPIENT_ADDRESS = ""
HOST_ADDRESS = ""
HOST_PORT =
#connection to server
server = smtplib.SMTP(host=HOST_ADDRESS, port=HOST_PORT)
server.starttls()
server.login(MY_ADDRESS, MY_PASSWORD)
#create mime multipart object
message = MIMEMultipart()
#mime multipart object header
message['From'] = MY_ADDRESS
message['To'] = RECIPIENT_ADDRESS
message['Subject'] = "Automated Email with Attachment"
#mime text
textPart = MIMEText("Did it work?", 'plain')
#mime application
filename = "document.txt"
filePart = MIMEApplication(open(filename,"rb").read(),Name=filename)
filePart["Content-Disposition"] = 'attachment; filename="%s' % filename
#attach parts
message.attach(textPart)
message.attach(filePart)
#send message as many times as needed (this is what breaks it)
for i in range(5):
server.send_message(message)

