Commit 33acc6c4 authored by Gabriel Detraz's avatar Gabriel Detraz Committed by root

Reecriture partielle, utilisation d'une api mail custom

parent c4d28c97
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
from configparser import ConfigParser from configparser import ConfigParser
import socket import socket
from re2oapi import Re2oAPIClient from jinja2 import Environment, FileSystemLoader
from django.core.mail import send_mail
from django.template import loader, Context from re2oapi import Re2oAPIClient, ApiSendMail
from pprint import pprint from pprint import pprint
import sys import sys
...@@ -18,37 +18,46 @@ api_username = config.get('Re2o', 'username') ...@@ -18,37 +18,46 @@ api_username = config.get('Re2o', 'username')
api_client = Re2oAPIClient(api_hostname,api_username,api_password) api_client = Re2oAPIClient(api_hostname,api_username,api_password)
api_mailserver = config.get('Mail', 'mailserver')
api_port = config.get('Mail', 'port')
api_sendmail = ApiSendMail(api_mailserver, api_port)
client_hostname = socket.gethostname().split('.',1)[0] client_hostname = socket.gethostname().split('.',1)[0]
for arg in sys.argv: # Création de l'environnement Jinja
if arg=="--force": ENV = Environment(loader=FileSystemLoader('.'))
notif_end_adhesion(api_client)
def notif_end_adhesion(api_client): def notif_end_adhesion(api_client):
asso_options = api_client.list("preferences/assooption") asso_options = api_client.view("preferences/assooption/")
from_mail = api_client.list("preferences/generaloption")["email_from"] general_options = api_client.view("preferences/generaloption/")
template = loader.get_template('email_fin_adhesion') template = ENV.get_template("templates/email_fin_adhesion")
for result in api_client.list("reminder/get-users"): for result in api_client.list("reminder/get-users"):
for user in result["users_to_remind"]: for user in result["users_to_remind"]:
context = Context({ if "--verbose" in sys.argv:
'nom': user["get_full_name"], print('Mail envoyé à {}, reminder {} days'.format(user["get_full_name"],result["days"]))
'temps': result["days"], reminder_mail = template.render(
'asso_name': asso_options["name"], nom=user["get_full_name"],
'link': asso_options["site_url"] temps=result["days"],
}) asso_name=asso_options["name"],
print('mail envoyé à {}, reminder {} days'.format(user["get_full_name"],result["days"])) message=result["message"],
send_mail("Avis de fin d'adhésion / End of subscription notice", link=general_options["main_site_url"])
'', api_sendmail.send_mail(
from_mail, general_options["email_from"],
user["email"], user["get_mail"],
html_message = template.render(context) "Avis de fin d'adhésion / End of subscription notice",
reminder_mail
) )
## Manual command
if "--force" in sys.argv:
notif_end_adhesion(api_client)
## Automatic regen
for service in api_client.list("services/regen/"): for service in api_client.list("services/regen/"):
if service['hostname'] == client_hostname and \ if service['hostname'] == client_hostname and \
service['service_name'] == 'mail' and \ service['service_name'] == 'notif-users' and \
service['need_regen']: service['need_regen']:
notif_end_adhesion(api_client) notif_end_adhesion(api_client)
api_client.patch(service['api_url'], data={'need_regen': False}) api_client.patch(service['api_url'], data={'need_regen': False})
<p>Bonjour {{nom}},</p> <p>Bonjour {{nom}},</p>
<P>Ton adhésion arrive à son therme dans {{temps}} jours.</P> <p>Ta connexion internet va expirer dans {{temps}} jours.</p>
{% if online %} {{message}}
<p>Tu peux renouveller ton adhésion en ligne sur <a href"{{link}}">Mon Profil</a>.</p>
<p>Tu peux également contacter un membre de {{asso_name}} pour renouveller ton adhésion</p>
{% else %}
<p>Pour renouveller ton adhésion, contacte un membre de {{asso_name}}.</p>
{% endif %}
<p>A bientôt.</p> <p>Tu peux gérer ta connexion en ligne sur <a href={{link}}>Mon profil</a></p>
<p>Tu peux bien évidemment également contacter un membre de {{asso_name}} pour renouveller ton adhésion</p>
<p>A bientôt !</p>
<hr> <hr>
<p>Hi {{nom}},</p> <p>Hi {{nom}},</p>
<P>Your subscription comes to an end in {{temps}} days.</P> <p>Your subscription comes to an end in {{temps}} days.</p>
{% if online %} <p>You can manage it online on <a href={{link}}>My Profil</a>.</p>
<p>You can renew it online on <a href"{{link}}">My Profil</a>.</p>
<p>You can also contat a member of {{asso_name}} to renew it.</p> <p>You can also contat a member of {{asso_name}} to renew it.</p>
{% else %}
<p>To renew it, contact a member of {{asso_name}}</p>
{% endif %}
<p>Regards.</p> <p>Regards.</p>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment