diff --git a/groupTasks/groups/shx-order-voucher-code-activated/index.json b/groupTasks/groups/shx-order-voucher-code-activated/index.json new file mode 100644 index 0000000..67158e6 --- /dev/null +++ b/groupTasks/groups/shx-order-voucher-code-activated/index.json @@ -0,0 +1,33 @@ +{ + "category": "Shinnex", + "name": "Gutscheincode freigeschaltet", + "globalInputs": [], + "tasks": [ + { + "name": "Gutscheincode per E-Mail an Kunden senden", + "onFinish": "next", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "script.py", + "parameters": [ + { + "parameterName": "customer_email", + "type": "text", + "displayName": "E-Mail vom Kunden" + }, + { + "parameterName": "voucher_code", + "type": "text", + "displayName": "Gutscheincode für den Kunden (in Shopify erstellen)" + }, + { + "parameterName": "voucher_type", + "type": "select", + "displayName": "Gutschein Typ", + "options": ["5 €", "10 €"], + "global": false + } + ] + } + ] +} \ No newline at end of file diff --git a/groupTasks/groups/shx-order-voucher-code-activated/script.py b/groupTasks/groups/shx-order-voucher-code-activated/script.py new file mode 100644 index 0000000..3946487 --- /dev/null +++ b/groupTasks/groups/shx-order-voucher-code-activated/script.py @@ -0,0 +1,87 @@ +import json +import sys +import yaml +import smtplib +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText + +STATIC_PATH = "../../groupsData/shx-order-voucher-code-activated/" + +json_object = json.loads(sys.argv[1]) +customer_email = json_object["customer_email"] +voucher_code = json_object["voucher_code"] +voucher_type = json_object["voucher_type"] + +if (customer_email is None + or voucher_code is None + or voucher_type is None): + print("Missing required parameters") + sys.exit(1) + +customer_email = customer_email["value"] +voucher_code = voucher_code["value"] +voucher_type = voucher_type["value"] + +def load_email_config(filename): + with open(filename, "r") as f: + config = yaml.safe_load(f) + return config["email"], config["smtp"] + +email_config, smtp_config = load_email_config(f"{STATIC_PATH}config.yml") + +# extract the email parameters +auth_email = email_config["auth_email"] +from_email_name = email_config["from_email_name"] +from_email = email_config["from_email"] +password = email_config["password"] + +# extract the smtp parameters +smtp_server = smtp_config["server"] +smtp_port = smtp_config["port"] + +receiver_email = customer_email + +# create the email multipart message +msg = MIMEMultipart("alternative") +msg["From"] = f"{from_email_name} <{from_email}>" +msg["To"] = receiver_email +msg["Subject"] = f"{voucher_type} Gutschein als Dankeschön" + +# load html content from file +with open(f"{STATIC_PATH}email.txt", "r") as file: + text = file.read() + +with open(f"{STATIC_PATH}email.html", "r") as file: + html = file.read() + +# replace placeholders with actual values + +if voucher_type == "5 €": + message = "Wir haben deine Bewertung überprüft und möchten dir als Dankeschön einen 5 € Gutschein überreichen." +else: + message = "Wir haben deinen Beitrag auf Instagram überprüft und möchten dir als Dankeschön einen 10 € Gutschein überreichen." + +html = html.replace("{{MESSAGE}}", message) +html = html.replace("{{VOUCHER_CODE}}", voucher_code) + +text = text.replace("{{MESSAGE}}", message) +text = text.replace("{{VOUCHER_CODE}}", voucher_code) + +# add text and html part to the email +part1 = MIMEText(text, "plain", "utf-8") +part2 = MIMEText(html, "html", "utf-8") + +# Attach the text and html part to the email +msg.attach(part1) +msg.attach(part2) + +# connect to the smtp server and send the email +try: + with smtplib.SMTP_SSL(smtp_server, smtp_port) as server: + server.login(auth_email, password) + server.sendmail(from_email, receiver_email, msg.as_string()) + + print(f"Email sent to {receiver_email} with voucher code {voucher_code} of type {voucher_type}") +except Exception as e: + print(f"Error sending email: {e}") + sys.exit(1) \ No newline at end of file diff --git a/groupTasks/groupsData/shx-order-voucher-code-activated/config.yml b/groupTasks/groupsData/shx-order-voucher-code-activated/config.yml new file mode 100644 index 0000000..e0bd9c2 --- /dev/null +++ b/groupTasks/groupsData/shx-order-voucher-code-activated/config.yml @@ -0,0 +1,8 @@ +email: + auth_email: jan.umbach@jannex.de + from_email_name: Shinnex + from_email: info@shinnex.de + password: WhBPcHifjN5pg6LOhSRxMJ8KX3BT3gUo +smtp: + server: smtp.mailbox.org + port: 465 diff --git a/groupTasks/groupsData/shx-order-voucher-code-activated/email.html b/groupTasks/groupsData/shx-order-voucher-code-activated/email.html new file mode 100644 index 0000000..8f74e66 --- /dev/null +++ b/groupTasks/groupsData/shx-order-voucher-code-activated/email.html @@ -0,0 +1,280 @@ + + + + + + + + + + + + + + +
+ + + + + + +
+
+ + + + + + + +
+ + + + + + +
+ Shinnex +
+
+
+
+ + + + + + + + +
+
+ + + + + + +
+

+ Dein Gutschein als Dankeschön +

+

+ {{MESSAGE}} Du kannst den Gutschein beim + Checkout einlösen. +

+
+ +

+ Dein Gutscheincode lautet: + {{VOUCHER_CODE}} +

+ + + + + + +
+ + + + + + +
+ Zu unserem Shop +
+
+
+
+
+ + + + + + + + + +
+ + diff --git a/groupTasks/groupsData/shx-order-voucher-code-activated/email.txt b/groupTasks/groupsData/shx-order-voucher-code-activated/email.txt new file mode 100644 index 0000000..bbb06b3 --- /dev/null +++ b/groupTasks/groupsData/shx-order-voucher-code-activated/email.txt @@ -0,0 +1,9 @@ +Dein Gutscheincode als Dankeschön + +{{MESSAGE}} Du kannst den Gutschein beim Checkout einlösen. + +Dein Gutscheincode lautet: {{VOUCHER_CODE}} + +Zu unserem Shop: https://shinnex.de + +Falls du Fragen hast, antworte auf diese E-Mail oder kontaktiere uns unter info@shinnex.de. \ No newline at end of file