mail_module: context manager pour connexion smtp
This commit is contained in:
parent
028d6bdbac
commit
99983b69cc
1 changed files with 11 additions and 0 deletions
|
@ -6,6 +6,7 @@ import sys
|
||||||
import json
|
import json
|
||||||
import inspect
|
import inspect
|
||||||
import locale
|
import locale
|
||||||
|
import smtplib
|
||||||
|
|
||||||
from email.header import Header
|
from email.header import Header
|
||||||
from email.message import Message
|
from email.message import Message
|
||||||
|
@ -149,3 +150,13 @@ def validation_url(view_name, data='', debug=False):
|
||||||
raise Exception('Bad code status %d' % req.status_code)
|
raise Exception('Bad code status %d' % req.status_code)
|
||||||
|
|
||||||
return ROOT + req.text.encode('utf-8')
|
return ROOT + req.text.encode('utf-8')
|
||||||
|
|
||||||
|
class ServerConnection(object):
|
||||||
|
"""Connexion au serveur smtp"""
|
||||||
|
_conn = None
|
||||||
|
def __enter__(self):
|
||||||
|
self._conn = smtplib.SMTP('smtp.adm.crans.org')
|
||||||
|
return self._conn
|
||||||
|
|
||||||
|
def __exit__(self, type, value, traceback):
|
||||||
|
self._conn.quit()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue