From e9c6312903715262a0bb73aaa4cb5ee0cfa68e5f Mon Sep 17 00:00:00 2001 From: GeoSot Date: Mon, 27 Mar 2023 19:42:27 +0300 Subject: [PATCH] feat: configurable email server --- emaildbmod.py | 21 ++++++++++++++++++++- emailmod.py | 2 +- networkdbmod.py | 4 +++- start.py | 10 ++++++++-- templates/systemmailsetting.html | 14 +++++++++++++- 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/emaildbmod.py b/emaildbmod.py index f3e3b70..d8c8e87 100755 --- a/emaildbmod.py +++ b/emaildbmod.py @@ -2,7 +2,7 @@ """ fertilizer UI setting storage utilities """ -from __future__ import print_function +from __future__ import print_function import logging import os @@ -57,6 +57,19 @@ def getpassword(): dataitem=filestoragemod.searchdata(DATAFILENAME,recordkey,recordvalue,keytosearch) return dataitem +def getserver(): + recordkey="name" + recordvalue="email" + keytosearch="server" + dataitem=filestoragemod.searchdata(DATAFILENAME,recordkey,recordvalue,keytosearch) + return dataitem + +def getport(): + recordkey="name" + recordvalue="email" + keytosearch="port" + dataitem=filestoragemod.searchdata(DATAFILENAME,recordkey,recordvalue,keytosearch) + return dataitem def changesavesetting(FTparameter,FTvalue): searchfield="name" @@ -92,10 +105,16 @@ def get_path(): # comment address="hello@mail.com" password="haha" + server="smtp.gmail.com" + port="587" changesavesetting("address",address) changesavesetting("password",password) + changesavesetting("server",server) + changesavesetting("port",port) print(getaddress()) print(getpassword()) + print(getserver()) + print(getport()) diff --git a/emailmod.py b/emailmod.py index b981b59..866a33e 100755 --- a/emailmod.py +++ b/emailmod.py @@ -43,7 +43,7 @@ def send_email(user, pwd, recipient, subject, body): message = """\From: %s\nTo: %s\nSubject: %s\n\n%s """ % (FROM, ", ".join(TO), SUBJECT, TEXT) try: - server = smtplib.SMTP("smtp.gmail.com", 587) + server = smtplib.SMTP(emaildbmod.getserver(), emaildbmod.getport()) server.ehlo() server.starttls() server.login(gmail_user, gmail_pwd) diff --git a/networkdbmod.py b/networkdbmod.py index c3b68f7..07a7d2e 100755 --- a/networkdbmod.py +++ b/networkdbmod.py @@ -156,7 +156,9 @@ def restoredefault(): #changesavesetting("password",password) #print getaddress() #print getpassword() - + #print getserver() + #print getport() + message="hello" storemessage(message) getstoredmessage() diff --git a/start.py b/start.py index e32a01b..7fe9baf 100755 --- a/start.py +++ b/start.py @@ -1416,9 +1416,13 @@ def systemmailsetting(): print("saving email credentials") address=request.form['address'] password=request.form['password'] + server=request.form['server'] + port=request.form['port'] isok1=emaildbmod.changesavesetting('address',address) isok2=emaildbmod.changesavesetting('password',password) - if isok1 and isok2: + isok3=emaildbmod.changesavesetting('server',server) + isok4=emaildbmod.changesavesetting('port',port) + if isok1 and isok2 and isok3 and isok4 : flash('Email credentials Saved') return redirect(url_for('show_Calibration')) elif reqtype=="cancel": @@ -1426,7 +1430,9 @@ def systemmailsetting(): password=emaildbmod.getpassword() address=emaildbmod.getaddress() - return render_template('systemmailsetting.html', address=address, password=password) + server=emaildbmod.getserver() + port=emaildbmod.getport() + return render_template('systemmailsetting.html', address=address, password=password, server=server, port=port) @application.route('/HC12setting/', methods=['GET', 'POST']) diff --git a/templates/systemmailsetting.html b/templates/systemmailsetting.html index 8015853..8339b29 100644 --- a/templates/systemmailsetting.html +++ b/templates/systemmailsetting.html @@ -23,7 +23,19 @@
- System Mail Credentials + System Mail Credentials (SMTP) +
+ +
+ +
+
+
+ +
+ +
+