Commit cf5f2a90 authored by Jordan Delorme's avatar Jordan Delorme

Script d'envoi des mails de réinscription

parent 1b6958c6
#!/bin/bash /usr/scripts/python.sh
# -*- coding: utf-8 -*-
import sys
import smtplib
from gestion import config
from gestion.affich_tools import cprint
from gestion import mail
import lc_ldap.shortcuts
# Attention, si à True envoie effectivement les mails
SEND=False
ldap_filter=u'(&(!(chbre=????))(chbre=*)(!(chbre=EXT))(paiement=2013)(aid=*))'
conn=lc_ldap.shortcuts.lc_ldap_readonly()
mailaddrs=set()
for adh in conn.search(ldap_filter):
if 'canonicalAlias' in adh.attrs.keys():
mailaddrs.add(str(adh['canonicalAlias'][0]))
elif 'mail' in adh.attrs.keys():
mailaddrs.add(str(adh['mail'][0]))
else:
raise ValueError("%r has nor mail nor canonicalAlias, only %s" % (adh, adh.attrs.keys()))
#mailaddrs=["David.Marshall@crans.org", "Bertrand.Bryche@crans.org", "Karima.Toiybou@crans.org", "Thomas.Marchandier@crans.org"]
if not SEND:
print "Va envoyer le message à %s personnes. Mettre la variable SEND à True effectuer l'envoi" % len(mailaddrs)
echecs=[]
conn_smtp=smtplib.SMTP('smtp.adm.crans.org')
for To in mailaddrs:
cprint(u"Envoi du mail à %s" % To)
mailtxt=mail.generate('reinscription', {'To':To}).as_string()
try:
if SEND:
conn_smtp.sendmail("cableurs@crans.org", (To,), mailtxt)
except:
cprint(u"Erreur lors de l'envoi à %s " % To, "rouge")
echecs.append(To)
conn_smtp.quit()
if echecs:
print "\nIl y a eu des erreurs :"
print echecs
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