Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: configurable email server #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion emaildbmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
fertilizer UI setting storage utilities
"""
from __future__ import print_function
from __future__ import print_function

import logging
import os
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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())



2 changes: 1 addition & 1 deletion emailmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion networkdbmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ def restoredefault():
#changesavesetting("password",password)
#print getaddress()
#print getpassword()

#print getserver()
#print getport()

message="hello"
storemessage(message)
getstoredmessage()
Expand Down
10 changes: 8 additions & 2 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,17 +1416,23 @@ 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":
return redirect(url_for('show_Calibration'))

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'])
Expand Down
14 changes: 13 additions & 1 deletion templates/systemmailsetting.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@

<form class="form-horizontal" action="{{ url_for('systemmailsetting') }}" method="post">
<fieldset>
<legend>System Mail Credentials</legend>
<legend>System Mail Credentials (SMTP)</legend>
<div class="form-group">
<label for="inputServer" class="col-lg-3 control-label">Server address</label>
<div class="col-lg-9">
<input type="text" class="form-control" id="inputServer" placeholder={% if server=="" %}"mail server"{% else %}"{{server}}"{% endif %} name="server" value="{{server}}">
</div>
</div>
<div class="form-group">
<label for="inputPort" class="col-lg-3 control-label">Server port</label>
<div class="col-lg-9">
<input type="text" class="form-control" id="inputPort" placeholder={% if port=="" %}"mail port"{% else %}"{{port}}"{% endif %} name="port" value="{{port}}">
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-lg-3 control-label">Mail address</label>
<div class="col-lg-9">
Expand Down