Hello everybody,
I have a python-Script which sends E-Mails to my main account which I use as a notification method for birthdays.
Now I want to expand on that by adding an attachment (image).
Also, when possible, I like to send images from a pool of 5 pictures. Every time the script is started it should send one random image but without repeating them. When the script has been executed 5 times (all 5 images have been sent) it should reset and sent the images again (but in a new random order).
How can you do so?
This is my script so far:
I have a python-Script which sends E-Mails to my main account which I use as a notification method for birthdays.
Now I want to expand on that by adding an attachment (image).
Also, when possible, I like to send images from a pool of 5 pictures. Every time the script is started it should send one random image but without repeating them. When the script has been executed 5 times (all 5 images have been sent) it should reset and sent the images again (but in a new random order).
How can you do so?
This is my script so far:
#!/usr/bin/env python3 import smtplib import time f1 = open("../index/mail.txt","r") mail = f1.read() [:-1] f1.close() f2 = open("../index/passwd.txt","r") passwd = f2.read() [:-1] f2.close() f3 = open("../index/receiver.txt","r") receiver = f3.read() [:-1] f3.close() #Email Variables SMTP_SERVER = 'smtp.gmail.com' #Email Server (don't change!) SMTP_PORT = 587 #Server Port (don't change!) GMAIL_USERNAME = mail #change this to match your gmail account GMAIL_PASSWORD = passwd #change this to match your gmail password class Emailer: def sendmail(self, recipient, subject, content): #Create Headers headers = ["From: " + GMAIL_USERNAME, "Subject: " + subject, "To: " + recipient, "MIME-Version: 1.0", "Content-Type: text/html"] headers = "\r\n".join(headers) #Connect to Gmail Server session = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) session.ehlo() session.starttls() session.ehlo() #Login to Gmail session.login(GMAIL_USERNAME, GMAIL_PASSWORD) #Send Email & Exit msg = (headers + "\r\n\r\n" + content).encode('utf-8') session.sendmail(GMAIL_USERNAME, recipient, msg) session.quit sender = Emailer() sendTo = receiver emailSubject = "Subject" emailContent = "Content" #Sends an email to the "sendTo" address with the specified "emailSubject" as the subject and "emailConten$ sender.sendmail(sendTo, emailSubject, emailContent)