add logger to mail
This commit is contained in:
@@ -4,9 +4,14 @@ import sys
|
|||||||
from omegaconf import OmegaConf
|
from omegaconf import OmegaConf
|
||||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||||
|
|
||||||
|
from src.logic import log
|
||||||
|
|
||||||
from .dialog_sources.Ui_mail_preview import Ui_eMailPreview as Ui_Dialog
|
from .dialog_sources.Ui_mail_preview import Ui_eMailPreview as Ui_Dialog
|
||||||
|
|
||||||
config = OmegaConf.load("config.yaml")
|
config = OmegaConf.load("config.yaml")
|
||||||
|
from src.logic.log import MyLogger
|
||||||
|
|
||||||
|
logger = MyLogger("Mail")
|
||||||
|
|
||||||
|
|
||||||
class Mail_Dialog(QtWidgets.QDialog, Ui_Dialog):
|
class Mail_Dialog(QtWidgets.QDialog, Ui_Dialog):
|
||||||
@@ -64,7 +69,9 @@ class Mail_Dialog(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
|
|
||||||
def load_mail_templates(self):
|
def load_mail_templates(self):
|
||||||
print("loading mail templates")
|
print("loading mail templates")
|
||||||
|
|
||||||
mail_templates = os.listdir("mail_vorlagen")
|
mail_templates = os.listdir("mail_vorlagen")
|
||||||
|
logger.log_info(f"Mail templates: {mail_templates}")
|
||||||
for template in mail_templates:
|
for template in mail_templates:
|
||||||
self.comboBox.addItem(template)
|
self.comboBox.addItem(template)
|
||||||
|
|
||||||
@@ -104,12 +111,15 @@ class Mail_Dialog(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.mail_body.setHtml(mail_html)
|
self.mail_body.setHtml(mail_html)
|
||||||
|
logger.log_info(f"Mail template set to {email_template}")
|
||||||
|
|
||||||
def createAndSendMail(self):
|
def createAndSendMail(self):
|
||||||
|
logger.log_info("Sending mail")
|
||||||
import smtplib
|
import smtplib
|
||||||
import ssl
|
import ssl
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
|
|
||||||
tolist = [self.prof_mail, "semesterapparate@ph-freiburg.de"]
|
tolist = [self.prof_mail, "semesterapparate@ph-freiburg.de"]
|
||||||
self.btn_okay.setText("Mail wird gesendet")
|
self.btn_okay.setText("Mail wird gesendet")
|
||||||
smtp_server = config["mail"]["smtp_server"]
|
smtp_server = config["mail"]["smtp_server"]
|
||||||
@@ -120,7 +130,7 @@ class Mail_Dialog(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
message["From"] = sender_email
|
message["From"] = sender_email
|
||||||
message["To"] = self.prof_mail
|
message["To"] = self.prof_mail
|
||||||
message["Subject"] = self.mail_header.text()
|
message["Subject"] = self.mail_header.text()
|
||||||
#include a Fcc to the senders sent folder
|
# include a Fcc to the senders sent folder
|
||||||
message["cc"] = "semesterapparate@ph-freiburg.de"
|
message["cc"] = "semesterapparate@ph-freiburg.de"
|
||||||
|
|
||||||
mail_body = self.mail_body.toHtml()
|
mail_body = self.mail_body.toHtml()
|
||||||
@@ -139,7 +149,8 @@ class Mail_Dialog(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
print("Mail sent")
|
print("Mail sent")
|
||||||
# end active process
|
# end active process
|
||||||
server.quit()
|
server.quit()
|
||||||
#close the dialog
|
logger.log_info("Mail sent, closing connection to server and dialog")
|
||||||
|
# close the dialog
|
||||||
|
|
||||||
self.accept()
|
self.accept()
|
||||||
# # create a temporary file
|
# # create a temporary file
|
||||||
|
|||||||
Reference in New Issue
Block a user