Skip to content
Snippets Groups Projects
Commit d7ea8649 authored by Thomas Bock's avatar Thomas Bock :speech_balloon:
Browse files

from_mail must be valid

parent 5c021211
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python3 -u #!/usr/bin/python3 -u
import requests import requests
import json import json
...@@ -6,7 +6,10 @@ from datetime import datetime, timedelta ...@@ -6,7 +6,10 @@ from datetime import datetime, timedelta
db_url = "http://a73434.berlin.ptb.de:5984/vl_db/_design/share/_view/pla_date" db_url = "http://a73434.berlin.ptb.de:5984/vl_db/_design/share/_view/pla_date"
relay_url = "http://a73434.berlin.ptb.de:55555" relay_url = "http://a73434.berlin.ptb.de:55555"
to_mail = "thomas.bock@ptb.de"
to_mail = "vacuum.cal@ptb.de"
from_mail = to_mail
#to_mail = "thomas.bock@ptb.de"
post_days = 20 post_days = 20
pre_days = 90 pre_days = 90
...@@ -27,18 +30,24 @@ opening= { ...@@ -27,18 +30,24 @@ opening= {
body_post = { body_post = {
'en': "your reservation of the time slot {schedule_date} for calibration is about to expire.\nWould you like to order this calibration?", 'en': "your reservation of the time slot {schedule_date} for calibration is about to expire.\nWould you like to order this calibration?",
'de' : "die Reservierung Ihres Kalibriertermins zum {schedule_date} läuft in Kürze ab.\nMöchten Sie diese Kalibrierung in Auftrag geben?" 'de' : "die Reservierung Ihres Kalibriertermins zum {schedule_date} läuft in Kürze ab.\nMöchten Sie diese Kalibrierung in Auftrag geben?"
} }
body_pre = { body_pre = {
'de': "wir haben einen Kalibriertermin für Sie reserviert. Im Anhang finden Sie ein entsprechendes Angebot.\nBitte schicken Sie uns Ihre Bestellung innerhalb der nächsten 15 Werktage.", 'de': "wir haben einen Kalibriertermin für Sie reserviert. Im Anhang finden Sie ein entsprechendes Angebot.\nBitte schicken Sie uns Ihre Bestellung innerhalb der nächsten 15 Werktage.",
'en' : "we have reserved a time slot for your calibration. Please find attached the corresponding offer.\nPlease place your order within 15 working days. " 'en' : "we have reserved a time slot for your calibration. Please find attached the corresponding offer.\nPlease place your order within 15 working days. "}
}
closing = { closing = {
'en': "Best regards,", 'en': "Best regards,",
'de' : "Mit freundlichen Grüßen" 'de' : "Mit freundlichen Grüßen"
} }
sign ="\n".join( [
"Dr. Matthias Bernien Head of section Fon: ++49-30-3481-7230",
"Ute Becker Test leak Fon: ++49-30-3481-7467",
"Thomas Bock Ionisation gauge Fon: ++49-30-3481-7354",
"Christian Buchmann CDG, SRG Fon: ++49-30-3481-7415",
"Beate Prußeit Accounting Fon: ++49-30-3481-7375",])
subject_pre = { subject_pre = {
'en': "Angebot zur Kalibrierung am {date} (zum Weiterleiten an {email})", 'en': "Angebot zur Kalibrierung am {date} (zum Weiterleiten an {email})",
'de' : "Offer for calibration at {date} (zum Weiterleiten an {email})" 'de' : "Offer for calibration at {date} (zum Weiterleiten an {email})"
...@@ -46,14 +55,14 @@ subject_pre = { ...@@ -46,14 +55,14 @@ subject_pre = {
subject_post = { subject_post = {
'en': "Ihre Kalibrierung am {date} (zum Weiterleiten an {email})", 'en': "Ihre Kalibrierung am {date} (zum Weiterleiten an {email})",
'de' : "Your calibration at {date} (zum Weiterleiten an {email})" 'de' : "Your calibration at {schedule_datedate} (zum Weiterleiten an {email})"
} }
date_post_days = datetime.now() - timedelta(days=post_days) date_post_days = datetime.now() - timedelta(days=post_days)
ref_post_date = str(date_post_days).split(" ")[0] ref_post_date = str(date_post_days).split(" ")[0]
date_pre_days = datetime.now() + timedelta(days=pre_days) date_pre_days = datetime.now() + timedelta(days=pre_days)
ref_pre_date = str(date_pre_days).split(" ")[0] ref_pre_date = str(date_pre_days).split(" ")[0]
req_post = requests.get("{url}?key=\"{key}\"".format(url=db_url, key=ref_post_date)) req_post = requests.get("{url}?key=\"{key}\"".format(url=db_url, key=ref_post_date))
req_pre = requests.get("{url}?key=\"{key}\"".format(url=db_url, key=ref_pre_date)) req_pre = requests.get("{url}?key=\"{key}\"".format(url=db_url, key=ref_pre_date))
...@@ -76,21 +85,21 @@ for pla in plannings: ...@@ -76,21 +85,21 @@ for pla in plannings:
gender = contact.get("Gender", "none") gender = contact.get("Gender", "none")
email = contact.get("Email") email = contact.get("Email")
mail_opening = opening[gender][lang].format(name=name) mail_opening = opening[gender][lang].format(name=name)
if pla.get("match") == "pre": if pla.get("match") == "pre":
mail_subject = subject_pre[lang].format(date=ref_pre_date, email=email) mail_subject = subject_pre[lang].format(date=schedule_date, email=email)
mail_body = body_pre[lang].format(schedule_date=schedule_date) mail_body = body_pre[lang].format(schedule_date=schedule_date)
if pla.get("match") == "post": if pla.get("match") == "post":
mail_subject = subject_post[lang].format(date=ref_post_date, email=email) mail_subject = subject_post[lang].format(date=schedule_date, email=email)
mail_body = body_post[lang].format(schedule_date=schedule_date) mail_body = body_post[lang].format(schedule_date=schedule_date)
mail_closing = closing[lang] mail_closing = closing[lang]
mail = "{}\n\n{}\n\n{}".format(mail_opening, mail_body,mail_closing) mail = "{}\n\n{}\n\n{}\n\n\n{}".format(mail_opening, mail_body, mail_closing, sign)
task = {"Action":"EMAIL", task = {"Action":"EMAIL",
"Host": "smtp-hub.bs.ptb.de", "Host": "smtp-hub.bs.ptb.de",
"Subject": mail_subject, "Subject": mail_subject,
"From": "<reminder@ptb.de>", "From": "<{}>".format(from_mail),
"To": to_mail, "To": to_mail,
"Text": mail} "Text": mail}
print(task)
#req = requests.post(relay_url, data=json.dumps(task)) req = requests.post(relay_url, data=json.dumps(task))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment