Skip to content

Instantly share code, notes, and snippets.

@niran
Created February 23, 2011 19:33
Show Gist options
  • Select an option

  • Save niran/840999 to your computer and use it in GitHub Desktop.

Select an option

Save niran/840999 to your computer and use it in GitHub Desktop.

Revisions

  1. niran revised this gist Feb 23, 2011. 1 changed file with 20 additions and 0 deletions.
    20 changes: 20 additions & 0 deletions mail.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    from django.conf import settings
    import django.core.mail


    class MissingConnectionException(Exception):
    pass

    def get_connection(label=None, **kwargs):
    if label is None:
    label = getattr(settings, 'EMAIL_CONNECTION_DEFAULT', None)

    try:
    connections = getattr(settings, 'EMAIL_CONNECTIONS')
    options = connections[label]
    except KeyError, AttributeError:
    raise MissingConnectionException(
    'Settings for connection "%s" were not found' % label)

    options.update(kwargs)
    return django.core.mail.get_connection(**options)
  2. niran renamed this gist Feb 23, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. niran created this gist Feb 23, 2011.
    28 changes: 28 additions & 0 deletions email_settings.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    EMAIL_CONNECTIONS = {
    'gmail': {
    'host': 'smtp.gmail.com',
    'username': '[email protected]',
    'password': 'password',
    'port': 587,
    'use_tls': True,
    },
    'socketlabs': {
    'host': 'smtp.socketlabs-od.com',
    'username': 'blah',
    'password': 'password',
    'use_tls': False,
    },
    'ses': {
    'backend': 'django_ses.SESBackend',
    },
    'distributed': {
    'backend': 'tt.mail.backends.distributed.DistributedBackend',
    'components': (
    # Use SES for 8% of our emails. We send about 10,000 per day, so
    # 8% should keep us under our initial quota of 1,000.
    ('ses', 0.08),
    ('socketlabs', 0.92),
    ),
    }
    }
    EMAIL_CONNECTION_DEFAULT = 'distributed'