__version__ = '0.2.0' from django.core.mail.message import EmailMultiAlternatives import smtplib import logging from django.conf import settings # Get an instance of a logger LOGGER = logging.getLogger(__name__) def cookie_domain(c_domain = None): try: return getattr(settings, 'COOKIE_DOMAIN', c_domain) except AttributeError: import socket return socket.gethostname() def reset_password(): return getattr(settings, 'CC_RESET_PASSWORD', []) def _redirect_field_name(): return getattr(settings, 'REDIRECT_FIELD_NAME', 'r') def _token_field_name(): return getattr(settings, 'TOKEN_FIELD_NAME', 't') def auth_tkt_name(): return getattr(settings, 'AUTH_TKT_NAME', 'auth_tkt') def shared_secret(): return getattr(settings, 'SECURITY_SHAREDSECRET', 'sharedsecret') def ds_send_mail(mail_subject, msg, mail_from, to_email, log_msgs = [], attachments = None, send_html=True, cc=None): ''' **attachment** is a list of triples (filename, content, mimetype) ''' try: email = EmailMultiAlternatives(mail_subject, msg, mail_from, to_email, cc=cc) if attachments: for att in attachments: email.attach(att[0], att[1], att[2]) if send_html: html_msg = "" + msg + "" email.attach_alternative(html_msg, "text/html") email.message().as_string() email.send() except smtplib.SMTPException: for lmsg in log_msgs: LOGGER.error("Error sending email %s" % lmsg) for lmsg in log_msgs: LOGGER.info(lmsg)