|
@@ -0,0 +1,60 @@
|
|
|
+from flask import Flask, request
|
|
|
+from flask_mail import Message, Mail
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+mail = Mail()
|
|
|
+
|
|
|
+app = Flask(__name__, instance_relative_config=True)
|
|
|
+
|
|
|
+app.config.from_mapping(
|
|
|
+ MAIL_SERVER='mail.promocollection.com.au',
|
|
|
+ MAIL_PORT=465,
|
|
|
+ MAIL_USERNAME='info@promocollection.com.au',
|
|
|
+ MAIL_PASSWORD='&rA4v((=?a+6',
|
|
|
+ MAIL_USE_SSL=True,
|
|
|
+)
|
|
|
+
|
|
|
+mail.init_app(app)
|
|
|
+
|
|
|
+@app.route('/')
|
|
|
+def main():
|
|
|
+ return 'ok'
|
|
|
+
|
|
|
+@app.route('/sendmail', methods=['GET'])
|
|
|
+def sendmail():
|
|
|
+ if request.method == 'GET':
|
|
|
+ code = request.args.get('code')
|
|
|
+ if code == 'newregister':
|
|
|
+ html = request.args.get('html', '')
|
|
|
+ subject = request.args.get('subject', '')
|
|
|
+ to = request.args.get('to', '')
|
|
|
+
|
|
|
+ if html == '' or subject == '' or to == '':
|
|
|
+ return 'failed'
|
|
|
+ else:
|
|
|
+ subject = 'Supplier Code Update'
|
|
|
+ to = 'finance@promocollection.com.au'
|
|
|
+ ori = request.args.get('ori', '')
|
|
|
+ new = request.args.get('new', '')
|
|
|
+
|
|
|
+ html = """
|
|
|
+ <p>Product Code: %s</p>
|
|
|
+ <p>Original Supplier Code: %s</p>
|
|
|
+ <p><p>New Supplier Code: %s</p>
|
|
|
+ """ % (code, ori, new)
|
|
|
+
|
|
|
+ if ori == '' or new == '' or code == '':
|
|
|
+ return 'failed'
|
|
|
+
|
|
|
+ try:
|
|
|
+ msg = Message(subject=subject, sender='info@promocollection.com.au', recipients=[to], html=html)
|
|
|
+ mail.send(msg)
|
|
|
+
|
|
|
+ return 'success'
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return 'failed'
|
|
|
+
|
|
|
+
|