DBG_MAIL: environnement de test
This commit is contained in:
parent
7a546f44e1
commit
f1c5001f8e
2 changed files with 21 additions and 4 deletions
|
@ -50,7 +50,7 @@ markup = {
|
|||
'md' : markdown,
|
||||
}
|
||||
|
||||
### For an example:
|
||||
### For an example:
|
||||
### print generate('bienvenue', {'From':'respbats@crans.org', 'To':'admin@genua.fr', 'lang_info':'English version below'}).as_string()
|
||||
### or from a shell : python -c "import mail; print mail.generate('bienvenue', {'From':'respbats@crans.org', 'To':'admin@genua.fr', 'lang_info':'English version below'})"
|
||||
|
||||
|
@ -70,7 +70,7 @@ def get_lang(mail, part, lang, lang_fallback):
|
|||
if os.path.isfile(template_path + mail + '/' + part + '/' + l):
|
||||
return l, None, template_path + mail + '/' + part + '/' + l
|
||||
raise ValueError("Language %s nor %s found" % (lang, lang_fallback))
|
||||
|
||||
|
||||
def gen_local_body(fname, params, lang):
|
||||
"""Génère le texte localisé d'un body"""
|
||||
locales = {
|
||||
|
@ -123,7 +123,7 @@ def generate(mail, params, lang=default_language, lang_fallback=default_language
|
|||
for filename in [dir for dir in os.listdir(template_path + mail) if os.path.isdir(template_path + mail + '/' + dir)]:
|
||||
lang_tmp, mk, file = get_lang(mail, filename, lang, lang_fallback)
|
||||
|
||||
if filename == 'body':
|
||||
if filename == 'body':
|
||||
for part in body(mail, lang_tmp, lang_alt, mk, params, charset):
|
||||
msg.attach(part)
|
||||
else:
|
||||
|
@ -162,7 +162,17 @@ class ServerConnection(object):
|
|||
_conn = None
|
||||
def __enter__(self):
|
||||
self._conn = smtplib.SMTP('smtp.adm.crans.org')
|
||||
return self._conn
|
||||
return self
|
||||
|
||||
def sendmail(self, From, to, mail):
|
||||
if os.getenv('DBG_MAIL', False):
|
||||
deb = os.getenv('DBG_MAIL')
|
||||
if '@' in deb:
|
||||
to = [deb]
|
||||
else:
|
||||
print mail
|
||||
return
|
||||
self._conn.sendmail(From, to, mail)
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
self._conn.quit()
|
||||
|
|
|
@ -4,3 +4,10 @@
|
|||
# Utiliser ldap local
|
||||
export DBG_LDAP=1
|
||||
|
||||
# Mails auto, plusieurs valeurs:
|
||||
# * print: affiche le mail au lieu de l'envoyer
|
||||
# * une adresse mail: envoie tous les mails à cette adresse mail au lieu de
|
||||
# la vraie
|
||||
# NB: noter que pour le moment, cela ne marche pas avec tous les scripts.
|
||||
# Attention à ne pas envoyer de mails aux adhérents par erreurs !
|
||||
export DBG_MAIL=dstan+test@crans.org
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue