Skip to main content

Emails and SMSs managing framework for Django

Project description

Django MSGS

This small framework provides you with a set of flexible tools for implementing the message sending functionality.
Any type of informational messaging are available: emails, sms, telegram...

Installation

pip install django-msgs

settings.py:

INSTALLED_APPS = [
...
'msgs',
]

Apply the migrations for creation the tables at your database:

./manage.py migrate msgs

Structure

Django MSGS contains two common data models: Message and Template. The first one stores your messages, the second one describes the messaging templates.
If you need new type of email, you should create new Tpl with the HTML inside. After that you can use it for sending messages with this template.
By default Django MSGS provide you with three proxy models: Email, SMS and Message. You can customize them on your taste.
Also you can find a template model for any type of message: EmailTemplate, SMSTemplate and MessageTemplate.

Quick example

Look at the admin interface and create some templates for your messages.

Now we can use them for sending messages:

from msgs.models import Email

template_key = 'registration'  # a unique key for search the template
Email.create(
    template=template_key,
    recipient='john.doe@example.com',
    context={
        'name': 'John Doe',
        'link': 'https://example.com/registration',
    },
).send()

If you need i18n options, you can just inherit the existing template models with adding the needed language fields and use the send method with a language prefix as you need.

Let's look at the one more very useful attribute -- related_to. This library uses a generic foreign key for linking messages with another objects. You should provide this object when you create a message.

from msgs.models import SMS

instance = new_user  # this is an object you want to link with the email

SMS.create(
    template='registration',
    recipient='1234567890',
    context={
        'name': 'John Doe',
        'link': 'https://example.com/registration',
    },
    related_to=instance,  # it does the trick
).send()

Providers

The Django MSGS works with multiple providers. All of them are placed at the providers folder. So you can discover them and choose what you need.

You can find the BaseProvider class, hence nobody can stop you to build your own provider.

Settings

MSGS = {
    'providers': {
        'sendgrid': {
            'backend': 'msgs.providers.sendgrid.SendgridProvider',  # use SendGrid Provider
            'options': {
                'is_active': True,  # turn on/off sending messages
                'api_key': 'api-key',
                'sender': 'sender@email.com',
            },
        },
        'telegram': {
            'backend': 'msgs.providers.telegram.TelegramProvider',
            'options': {
                'is_active': False,
                'token': 'telegram-bot-token',
                'chat': 'chat-id',
            },
        },
    },
    'options': {
        'default_language': 'en',
    },
    'development': 'telegram',  # what use on development (not works properly, be careful)
    'email': 'sendgrid',  # use SendGrid Provider for sending emails
    'sms': 'telegram',  # use Telegram Provider for sending sms
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_msgs-1.7.7.tar.gz (22.5 kB view details)

Uploaded Source

File details

Details for the file django_msgs-1.7.7.tar.gz.

File metadata

  • Download URL: django_msgs-1.7.7.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for django_msgs-1.7.7.tar.gz
Algorithm Hash digest
SHA256 8f75d2cf3816c6f961b741199dda6387704bee127c8fdea380fc22b5dadf37a8
MD5 e5b76889661f24b7132bc56f99f1cca8
BLAKE2b-256 f314e12ce6bef5e45d6acf5f3007d0588f823b06905c7b61af82ed9e2061d1b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page