Kolbynko / Covid-tracker

1 stars 0 forks source link

Posielanie emailov #6

Open Kolbynko opened 2 years ago

lukvasson99 commented 2 years ago

print("1 = bez kontaktu s pozitívnym") print("2 = kontakt s pozitívnym") print("3 = pozitívny test")

x = input("Zadajte číslo podla tvojej situacie: ") if x=="1":print('Nič sa nedeje') elif x=="2":print('Sprav si ag test') elif x=="3":print('14 dní karanténa4') else:print("Zadal si nespravny argument")

Kolbynko commented 2 years ago

import email,smtplib,ssl from string import Template from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText

Template declaration

finalTemplate=""

templateName1="Template 1.txt" templateName2="Template 2.txt" templateName3="Template 3.txt" templateName4="Template 4.txt"

Creates template

def createTemplate(template): with open(template, 'r', encoding='utf-8') as template_file: template_file_content = template_file.read() return Template(template_file_content)

Picks template for different situations

def templatePicker(v_kontakte, ockovany, vysledok_testu): if v_kontakte and ockovany: finalTemplate=createTemplate(templateName1)

elif v_kontakte==False and vysledok_testu==False: finalTemplate=createTemplate(templateName2)

elif vysledok_testu: finalTemplate=createTemplate(templateName3)

elif v_kontakte and ockovany==False: finalTemplate=createTemplate(templateName4)

else: print("Creating template - FAILED")

return finalTemplate

def createMessage(name, email):

Set up smtp connection

s = smtplib.SMTP(host="MartinKollar@s.zochova.sk", port=587) s.starttls() if (s.login("MartinKollar@s.zochova.sk", "Zochova2244")): print("SMTP connection - OK") else: print("SMTP connection - FAILED")

msg = MIMEMultipart() #creates a message

Creates message out of template with proper name

message = finalTemplate.substitute(PERSON_NAME=name.title())

msg['From']="MartinKollar@s.zochova.sk" msg['To']=email msg['Subject']="Covid-Informator"

Add in the message body

msg.attach(MIMEText(message, 'plain'))

Send the message via the server set up earlier.

s.send_message(msg)

del msg

createMessage("Tomas", "bubeniktomi@gmail.com")