voucher code activated

main
alex 2024-04-19 23:08:16 +02:00
parent a70a3affbe
commit 04397ce7c9
5 changed files with 417 additions and 0 deletions

View File

@ -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
}
]
}
]
}

View File

@ -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)

View File

@ -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

View File

@ -0,0 +1,280 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
/* CSS-Stile hier */
</style>
</head>
<body style="margin: 0">
<!-- Kopfzeile -->
<table
class="body"
style="
height: 100% !important;
width: 100% !important;
border-spacing: 0;
border-collapse: collapse;
"
>
<tbody>
<tr>
<td style="font-family: Arial, sans-serif">
<table
class="header row"
style="
width: 100%;
border-spacing: 0;
border-collapse: collapse;
margin: 40px 0 20px;
"
>
<tbody>
<tr>
<td
class="header__cell"
style="font-family: Arial, sans-serif"
>
<center>
<!-- Logo einfügen -->
<table
class="container"
style="
width: 560px;
text-align: left;
border-spacing: 0;
border-collapse: collapse;
margin: 0 auto;
"
>
<tbody>
<tr>
<td style="font-family: Arial, sans-serif">
<table
class="row"
style="
width: 100%;
border-spacing: 0;
border-collapse: collapse;
"
>
<tbody>
<tr>
<td
class="shop-name__cell"
style="font-family: Arial, sans-serif"
>
<img
src="https://cdn.shopify.com/s/files/1/0830/6881/3652/files/Final_logo_black_social_sharing.png?341"
alt="Shinnex"
width="180"
/>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</center>
</td>
</tr>
</tbody>
</table>
<!-- Inhalt -->
<table
class="row content"
style="width: 100%; border-spacing: 0; border-collapse: collapse"
>
<tbody>
<tr>
<td
class="content__cell"
style="
font-family: Arial, sans-serif;
padding-bottom: 40px;
border-width: 0;
"
>
<center>
<table
class="container"
style="
width: 560px;
text-align: left;
border-spacing: 0;
border-collapse: collapse;
margin: 0 auto;
"
>
<tbody>
<tr>
<td style="font-family: Arial, sans-serif">
<h2
style="
font-weight: normal;
font-size: 24px;
margin: 0 0 10px;
"
>
Dein Gutschein als Dankeschön
</h2>
<p
style="
color: #777;
line-height: 150%;
font-size: 16px;
margin: 0;
"
>
{{MESSAGE}} Du kannst den Gutschein beim
Checkout einlösen.
</p>
<br />
<!-- Gutscheincode hier einfügen -->
<p
style="
color: #777;
line-height: 150%;
font-size: 16px;
margin: 0;
"
>
Dein Gutscheincode lautet:
<strong>{{VOUCHER_CODE}}</strong>
</p>
<table
class="row actions"
style="
width: 100%;
border-spacing: 0;
border-collapse: collapse;
margin-top: 20px;
"
>
<tbody>
<tr>
<td
class="actions__cell"
style="font-family: Arial, sans-serif"
>
<table
class="button main-action-cell"
style="
border-spacing: 0;
border-collapse: collapse;
float: left;
margin-right: 15px;
"
>
<tbody>
<tr>
<td
class="button__cell"
style="
font-family: Arial, sans-serif;
border-radius: 4px;
"
align="center"
bgcolor="#af9363"
>
<a
href="https://shinnex.de"
class="button__text"
style="
font-size: 16px;
text-decoration: none;
display: block;
color: #fff;
padding: 20px 25px;
"
>Zu unserem Shop</a
>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</center>
</td>
</tr>
</tbody>
</table>
<!-- Fußzeile -->
<table
class="row footer"
style="
width: 100%;
border-spacing: 0;
border-collapse: collapse;
border-top-width: 1px;
border-top-color: #e5e5e5;
border-top-style: solid;
"
>
<tbody>
<tr>
<td
class="footer__cell"
style="font-family: Arial, sans-serif; padding: 35px 0"
>
<center>
<table
class="container"
style="
width: 560px;
text-align: left;
border-spacing: 0;
border-collapse: collapse;
margin: 0 auto;
"
>
<tbody>
<tr>
<td style="font-family: Arial, sans-serif">
<p
class="disclaimer__subtext"
style="
color: #999;
line-height: 150%;
font-size: 14px;
margin: 0;
"
>
Falls du Fragen hast, antworte auf diese E-Mail
oder kontaktiere uns unter
<a
href="mailto:info@shinnex.de"
style="
font-size: 14px;
text-decoration: none;
color: #af9363;
"
>info@shinnex.de</a
>.
</p>
</td>
</tr>
</tbody>
</table>
</center>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>

View File

@ -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.