omic-django-herald


Nameomic-django-herald JSON
Version 0.2.1.21 PyPI version JSON
download
home_pagehttps://github.com/vvkvivekl/omic-django-herald/
SummaryDjango library for separating the message content from transmission method
upload_time2023-07-31 03:01:33
maintainer
docs_urlNone
authorPred Health
requires_python
licenseMIT
keywords django notifications messaging
VCS
bugtrack_url
requirements six mock jsonpickle twilio coveralls pytz html2text
Travis-CI
coveralls test coverage
            # django-herald-msg91

[![Latest PyPI version](https://badge.fury.io/py/mindbogglr-django-herald.svg)](https://pypi.python.org/pypi/mindbogglr-django-herald)

Forked from: [django-herald](https://github.com/worthwhile/django-herald/tree/a0da436e003829b72b87b2bcfdc4d0e5e4449adb)

I've added support for sending messages using the [msg91](https://msg91.com/) platform backend for sending text messages (SMS) in India.

Please go over the installation steps mentioned in the [original ReadMe](https://github.com/worthwhile/django-herald/tree/a0da436e003829b72b87b2bcfdc4d0e5e4449adb)

# Differences in setup:

### Installation
`pip install mindbogglr-django-herald`

### Settings
In your Django settings file, add the following settings:
```
MSG91_TRANSACTIONAL_SENDER_ID = 'SOCKET'
MSG91_AUTHKEY = '228352HGNg5dF65b57672G'
```
Replace 'SOCKET' with any 6 alphebet series that you want in the user's text message inbox.
Replace '228352HGNg5dF65b57672G' with your authkey from your [msg91](https://msg91.com/) account

**Note:** it'll show up as BT-SOCKET or similar...the first two alphabets indicate the text message provider and the region and is not controllable.

### Usage
```python
from herald import registry
from herald.text_notification import Msg91TextNotification

@registry.register_decorator()
class InvitationMessage(Msg91TextNotification):
    template_name = 'invitation_message'  # name of template, without extension

    def __init__(self, to_number, invited_by_user, user_full_name, invitation_url):
        # set context for the template rendering
        self.context = {
            'invited_by_user': invited_by_user,
            'user_full_name': user_full_name,
            'invitation_url': invitation_url
        }

        self.to_number = to_number
```

# Original ReadMe
[![Logo](https://github.com/worthwhile/django-herald/raw/master/logo.png)](https://github.com/worthwhile/django-herald)

A Django messaging library that features:

- Class-based declaration and registry approach, like Django Admin
- Supports multiple transmission methods (Email, SMS, Slack, etc) per message
- Browser-based previewing of messages
- Maintains a history of messaging sending attempts and can view these messages
- Disabling notifications per user

# Python/Django Support

We try to make herald support all versions of django that django supports + all versions in between.

For python, herald supports all versions of python that the above versions of django support.

So as of herald v0.2 we support django 1.11, 2.0, 2.1, and 2.2, and python 2.7, 3.4, 3.5, 3.6, and 3.7.

## What version of herald do I need if I have django x and python x?

If the django/python version combination has a `---` in the table, it is not guaranteed to be supported.

|                   | py 2.7   | py 3.3   | py 3.4   | py 3.5   | py 3.6   | py 3.7   |
|:-----------------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|
| **dj 1.8**        | <0.2     | <0.2     | <0.2     | <0.2     | ---      | ---      |
| **dj 1.9 - 1.10** | <0.2     | ---      | <0.2     | <0.2     | ---      | ---      |
| **dj 1.11**       | \>=0.1.5 | ---      | \>=0.1.5 | \>=0.1.5 | \>=0.1.5 | ---      |
| **dj 2.0**        | ---      | ---      | \>=0.1.5 | \>=0.1.5 | \>=0.1.5 | \>=0.2   |
| **dj 2.1**        | ---      | ---      | ---      | \>=0.2   | \>=0.2   | \>=0.2   |
| **dj 2.2**        | ---      | ---      | ---      | \>=0.2   | \>=0.2   | \>=0.2   |


# Installation

1. `pip install django-herald`
2. Add `herald` and `django.contrib.sites` to `INSTALLED_APPS`.
3. Add herald's URLS:

    ```python
    if settings.DEBUG:
        urlpatterns = [
            url(r'^herald/', include('herald.urls')),
        ] + urlpatterns
    ```

# Usage

1. Create a `notifications.py` file in any django app. This is where your notification classes will live. Add a class like this:

```python
from herald import registry
from herald.base import EmailNotification


class WelcomeEmail(EmailNotification):  # extend from EmailNotification for emails
    template_name = 'welcome_email'  # name of template, without extension
    subject = 'Welcome'  # subject of email

    def __init__(self, user):  # optionally customize the initialization
        self.context = {'user': user}  # set context for the template rendering
        self.to_emails = [user.email]  # set list of emails to send to

    @staticmethod
    def get_demo_args():  # define a static method to return list of args needed to initialize class for testing
        from users.models import User
        return [User.objects.order_by('?')[0]]

registry.register(WelcomeEmail)  # finally, register your notification class

# Alternatively, a class decorator can be used to register the notification:

@registry.register_decorator()
class WelcomeEmail(EmailNotification):
    ...
```


2. Create templates for rendering the email using this file structure:

        templates/
            herald/
                text/
                    welcome_email.txt
                html/
                    welcome_email.html

3. Test how your email looks by navigating to `/herald/`.

4. Send your email wherever you need in your code:

        WelcomeEmail(user).send()

5. View the sent emails in django admin and even be able to resend it.

## Email options

The following options can be set on the email notification class. For Example:

```
class WelcomeEmail(EmailNotification):
    cc = ['test@example.com']
```

- `from_email`: (`str`, default: `settings.DEFAULT_FROM_EMAIL`) email address of sender
- `subject`: (`str`, default: ) email subject
- `to_emails`: (`List[str]`, default: `None`) list of email strings to send to
- `bcc`: (`List[str]`, default: `None`) list of email strings to send as bcc
- `cc`: (`List[str]`, default: `None`) list of email strings to send as cc
- `headers`: (`dict`, default: `None`) extra headers to be passed along to the `EmailMultiAlternatives` object
- `reply_to`: (`List[str]`, default: `None`) list of email strings to send as the Reply-To emails
- `attachments`: (`list`) list of attachments. See "Email Attachments" below for more info
    
    
## Automatically Deleting Old Notifications

Herald can automatically delete old notifications whenever a new notification is sent.

To enable this, set the `HERALD_NOTIFICATION_RETENTION_TIME` setting to a timedelta instance.

For example:

```
HERALD_NOTIFICATION_RETENTION_TIME = timedelta(weeks=8)
```

Will delete all notifications older than 8 weeks every time a new notification is sent.

## Manually Deleting Old Notifications

The `delnotifs` command is useful for purging the notification history.

The default usage will delete everything from sent during today:

```bash
python manage.py delnotifs
```

However, you can also pass arguments for `start` or `end` dates. `end` is up to, but not including that date.

```bash
python manage.py delnotifs --start='2016-01-01' --end='2016-01-10'
```


## Asynchronous Email Sending

If you are sending slightly different emails to a large number of people, it might take quite a while to process. By default, Django will process this all synchronously. For asynchronous support, we recommend django-celery-email. It is very straightfoward to setup and integrate: https://github.com/pmclanahan/django-celery-email


## herald.contrib.auth

Django has built-in support for sending password reset emails. If you would like to send those emails using herald, you can use the notification class in herald.contrib.auth.

First, add `herald.contrib.auth` to `INSTALLED_APPS` (in addition to `herald`).

Second, use the `HeraldPasswordResetForm` in place of django's built in `PasswordResetForm`. This step is entirely dependant on your project structure, but it essentially just involves changing the form class on the password reset view in some way:

```python
# you may simply just need to override the password reset url like so:
url(r'^password_reset/$', password_reset, name='password_reset', {'password_reset_form': HeraldPasswordResetForm}),

# of if you are using something like django-authtools:
url(r'^password_reset/$', PasswordResetView.as_view(form_class=HeraldPasswordResetForm), name='password_reset'),

# or you may have a customized version of the password reset view:
class MyPasswordResetView(FormView):
    form_class = HeraldPasswordResetForm  # change the form class here

# or, you may have a custom password reset form already. In that case, you will want to extend from the HeraldPasswordResetForm:
class MyPasswordResetForm(HeraldPasswordResetForm):
    ...

# alternatively, you could even just send the notification wherever you wish, seperate from the form:
PasswordResetEmail(some_user).send()
```

Third, you may want to customize the templates for the email. By default, herald will use the `registration/password_reset_email.html` that is provided by django for both the html and text versions of the email. But you can simply override `herald/html/password_reset.html` and/or `herald/text/password_reset.txt` to suit your needs.

## User Disabled Notifications

If you want to disable certain notifications per user, add a record to the UserNotification table and
add notifications to the disabled_notifications many to many table.

For example:

```python
user = User.objects.get(id=user.id)

notification = Notification.objects.get(notification_class=MyNotification.get_class_path())

# disable the notification
user.usernotification.disabled_notifications.add(notification)
```

By default, notifications can be disabled.  You can put can_disable = False in your notification class and the system will
populate the database with this default.  Your Notification class can also override the verbose_name by setting it in your
inherited Notification class.  Like this:

```python
class MyNotification(EmailNotification):
    can_disable = False
    verbose_name = "My Required Notification"
```

## Email Attachments

To send attachments, assign a list of attachments to the attachments attribute of your EmailNotification instance, or override the get_attachments() method.

Each attachment in the list can be one of the following:

1. A tuple which consists of the filename, the raw attachment data, and the mimetype. It is up to you to get the attachment data. Like this:

```python
raw_data = get_pdf_data()

email.attachments = [
    ('Report.pdf', raw_data, 'application/pdf'),
    ('report.txt', 'text version of report', 'text/plain')
]
email.send()
```

2. A MIMEBase object. See the documentation for attachments under EmailMessage Objects/attachments in the Django documentation.

3. A django `File` object.

### Inline Attachments

Sometimes you want to embed an image directly into the email content.  Do that by using a MIMEImage assigning a content id header to a MIMEImage, like this:

```python
email = WelcomeEmail(user)
im = get_thumbnail(image_file.name, '600x600', quality=95)
my_image = MIMEImage(im.read()) # MIMEImage inherits from MIMEBase
my_image.add_header('Content-ID', '<{}>'.format(image_file.name))
```

You can refer to these images in your html email templates using the Content ID (cid) like this:

```html
<img src="cid:{{image_file.name}}" />
```

You would of course need to add the "image_file" to your template context in the example above.  You can also accomplish this using file operations.  In this example we overrode the get_attachments method of an EmailNotification.

```python
class MyNotification(EmailNotification):
    context = {'hello': 'world'}
    template_name = 'welcome_email'
    to_emails = ['somebody@example.com']
    subject = "My email test"

    def get_attachments(self):
        fp = open('python.jpeg', 'rb')
        img = MIMEImage(fp.read())
        img.add_header('Content-ID', '<{}>'.format('python.jpeg'))
        return [
            img,
        ]
```

And in your template you would refer to it like this, and you would not need to add anything to the context:

```html
    <img src="cid:python.jpeg" />
```

### HTML2Text Support

Django Herald can auto convert your HTML emails to plain text.  Any email without a plain text version
will be auto converted if you enable this feature.

```
# Install html2text
pip install django-herald[html2text]
```

In your settings.py file:

```
HERALD_HTML2TEXT_ENABLED = True
```

You can customize the output of HTML2Text by setting a configuration dictionary. See 
[HTML2Text Configuration](https://github.com/Alir3z4/html2text/blob/master/docs/usage.md) for options

```
HERALD_HTML2TEXT_CONFIG = {
    # Key / value configuration of html2text 
    'ignore_images': True  # Ignores images in conversion
}
```

### Twilio

```
# Install twilio
pip install django-herald[twilio]
```

You can retrieve these values on [Twilio Console](https://twilio.com/console). Once you have retrieve the necessary ids, you can place those to your `settings.py`.

For reference, Twilio has some great tutorials for python.
[Twilio Python Tutorial](https://www.twilio.com/docs/sms/quickstart/python)

```
# Twilio configurations
# values taken from `twilio console`
TWILIO_ACCOUNT_SID = "your_account_sid"
TWILIO_AUTH_TOKEN = "your_auth_token"
TWILIO_DEFAULT_FROM_NUMBER = "+1234567890"

```

### Other MIME attachments

You can also attach any MIMEBase objects as regular attachments, but you must add a content-disposition header, or they will be inaccessible:

```python
my_image.add_header('Content-Disposition', 'attachment; filename="python.jpg"')
```

Attachments can cause your database to become quite large, so you should be sure to run the management commands to purge the database of old messages.

# Running Tests

```bash
python runtests.py
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vvkvivekl/omic-django-herald/",
    "name": "omic-django-herald",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "django,notifications,messaging",
    "author": "Pred Health",
    "author_email": "info@pred.health",
    "download_url": "https://files.pythonhosted.org/packages/80/87/87580869b171d01f829079b201726a2985fa79d108e3c4e2abbe95b9fe57/omic-django-herald-0.2.1.21.tar.gz",
    "platform": null,
    "description": "# django-herald-msg91\r\n\r\n[![Latest PyPI version](https://badge.fury.io/py/mindbogglr-django-herald.svg)](https://pypi.python.org/pypi/mindbogglr-django-herald)\r\n\r\nForked from: [django-herald](https://github.com/worthwhile/django-herald/tree/a0da436e003829b72b87b2bcfdc4d0e5e4449adb)\r\n\r\nI've added support for sending messages using the [msg91](https://msg91.com/) platform backend for sending text messages (SMS) in India.\r\n\r\nPlease go over the installation steps mentioned in the [original ReadMe](https://github.com/worthwhile/django-herald/tree/a0da436e003829b72b87b2bcfdc4d0e5e4449adb)\r\n\r\n# Differences in setup:\r\n\r\n### Installation\r\n`pip install mindbogglr-django-herald`\r\n\r\n### Settings\r\nIn your Django settings file, add the following settings:\r\n```\r\nMSG91_TRANSACTIONAL_SENDER_ID = 'SOCKET'\r\nMSG91_AUTHKEY = '228352HGNg5dF65b57672G'\r\n```\r\nReplace 'SOCKET' with any 6 alphebet series that you want in the user's text message inbox.\r\nReplace '228352HGNg5dF65b57672G' with your authkey from your [msg91](https://msg91.com/) account\r\n\r\n**Note:** it'll show up as BT-SOCKET or similar...the first two alphabets indicate the text message provider and the region and is not controllable.\r\n\r\n### Usage\r\n```python\r\nfrom herald import registry\r\nfrom herald.text_notification import Msg91TextNotification\r\n\r\n@registry.register_decorator()\r\nclass InvitationMessage(Msg91TextNotification):\r\n    template_name = 'invitation_message'  # name of template, without extension\r\n\r\n    def __init__(self, to_number, invited_by_user, user_full_name, invitation_url):\r\n        # set context for the template rendering\r\n        self.context = {\r\n            'invited_by_user': invited_by_user,\r\n            'user_full_name': user_full_name,\r\n            'invitation_url': invitation_url\r\n        }\r\n\r\n        self.to_number = to_number\r\n```\r\n\r\n# Original ReadMe\r\n[![Logo](https://github.com/worthwhile/django-herald/raw/master/logo.png)](https://github.com/worthwhile/django-herald)\r\n\r\nA Django messaging library that features:\r\n\r\n- Class-based declaration and registry approach, like Django Admin\r\n- Supports multiple transmission methods (Email, SMS, Slack, etc) per message\r\n- Browser-based previewing of messages\r\n- Maintains a history of messaging sending attempts and can view these messages\r\n- Disabling notifications per user\r\n\r\n# Python/Django Support\r\n\r\nWe try to make herald support all versions of django that django supports + all versions in between.\r\n\r\nFor python, herald supports all versions of python that the above versions of django support.\r\n\r\nSo as of herald v0.2 we support django 1.11, 2.0, 2.1, and 2.2, and python 2.7, 3.4, 3.5, 3.6, and 3.7.\r\n\r\n## What version of herald do I need if I have django x and python x?\r\n\r\nIf the django/python version combination has a `---` in the table, it is not guaranteed to be supported.\r\n\r\n|                   | py 2.7   | py 3.3   | py 3.4   | py 3.5   | py 3.6   | py 3.7   |\r\n|:-----------------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|\r\n| **dj 1.8**        | <0.2     | <0.2     | <0.2     | <0.2     | ---      | ---      |\r\n| **dj 1.9 - 1.10** | <0.2     | ---      | <0.2     | <0.2     | ---      | ---      |\r\n| **dj 1.11**       | \\>=0.1.5 | ---      | \\>=0.1.5 | \\>=0.1.5 | \\>=0.1.5 | ---      |\r\n| **dj 2.0**        | ---      | ---      | \\>=0.1.5 | \\>=0.1.5 | \\>=0.1.5 | \\>=0.2   |\r\n| **dj 2.1**        | ---      | ---      | ---      | \\>=0.2   | \\>=0.2   | \\>=0.2   |\r\n| **dj 2.2**        | ---      | ---      | ---      | \\>=0.2   | \\>=0.2   | \\>=0.2   |\r\n\r\n\r\n# Installation\r\n\r\n1. `pip install django-herald`\r\n2. Add `herald` and `django.contrib.sites` to `INSTALLED_APPS`.\r\n3. Add herald's URLS:\r\n\r\n    ```python\r\n    if settings.DEBUG:\r\n        urlpatterns = [\r\n            url(r'^herald/', include('herald.urls')),\r\n        ] + urlpatterns\r\n    ```\r\n\r\n# Usage\r\n\r\n1. Create a `notifications.py` file in any django app. This is where your notification classes will live. Add a class like this:\r\n\r\n```python\r\nfrom herald import registry\r\nfrom herald.base import EmailNotification\r\n\r\n\r\nclass WelcomeEmail(EmailNotification):  # extend from EmailNotification for emails\r\n    template_name = 'welcome_email'  # name of template, without extension\r\n    subject = 'Welcome'  # subject of email\r\n\r\n    def __init__(self, user):  # optionally customize the initialization\r\n        self.context = {'user': user}  # set context for the template rendering\r\n        self.to_emails = [user.email]  # set list of emails to send to\r\n\r\n    @staticmethod\r\n    def get_demo_args():  # define a static method to return list of args needed to initialize class for testing\r\n        from users.models import User\r\n        return [User.objects.order_by('?')[0]]\r\n\r\nregistry.register(WelcomeEmail)  # finally, register your notification class\r\n\r\n# Alternatively, a class decorator can be used to register the notification:\r\n\r\n@registry.register_decorator()\r\nclass WelcomeEmail(EmailNotification):\r\n    ...\r\n```\r\n\r\n\r\n2. Create templates for rendering the email using this file structure:\r\n\r\n        templates/\r\n            herald/\r\n                text/\r\n                    welcome_email.txt\r\n                html/\r\n                    welcome_email.html\r\n\r\n3. Test how your email looks by navigating to `/herald/`.\r\n\r\n4. Send your email wherever you need in your code:\r\n\r\n        WelcomeEmail(user).send()\r\n\r\n5. View the sent emails in django admin and even be able to resend it.\r\n\r\n## Email options\r\n\r\nThe following options can be set on the email notification class. For Example:\r\n\r\n```\r\nclass WelcomeEmail(EmailNotification):\r\n    cc = ['test@example.com']\r\n```\r\n\r\n- `from_email`: (`str`, default: `settings.DEFAULT_FROM_EMAIL`) email address of sender\r\n- `subject`: (`str`, default: ) email subject\r\n- `to_emails`: (`List[str]`, default: `None`) list of email strings to send to\r\n- `bcc`: (`List[str]`, default: `None`) list of email strings to send as bcc\r\n- `cc`: (`List[str]`, default: `None`) list of email strings to send as cc\r\n- `headers`: (`dict`, default: `None`) extra headers to be passed along to the `EmailMultiAlternatives` object\r\n- `reply_to`: (`List[str]`, default: `None`) list of email strings to send as the Reply-To emails\r\n- `attachments`: (`list`) list of attachments. See \"Email Attachments\" below for more info\r\n    \r\n    \r\n## Automatically Deleting Old Notifications\r\n\r\nHerald can automatically delete old notifications whenever a new notification is sent.\r\n\r\nTo enable this, set the `HERALD_NOTIFICATION_RETENTION_TIME` setting to a timedelta instance.\r\n\r\nFor example:\r\n\r\n```\r\nHERALD_NOTIFICATION_RETENTION_TIME = timedelta(weeks=8)\r\n```\r\n\r\nWill delete all notifications older than 8 weeks every time a new notification is sent.\r\n\r\n## Manually Deleting Old Notifications\r\n\r\nThe `delnotifs` command is useful for purging the notification history.\r\n\r\nThe default usage will delete everything from sent during today:\r\n\r\n```bash\r\npython manage.py delnotifs\r\n```\r\n\r\nHowever, you can also pass arguments for `start` or `end` dates. `end` is up to, but not including that date.\r\n\r\n```bash\r\npython manage.py delnotifs --start='2016-01-01' --end='2016-01-10'\r\n```\r\n\r\n\r\n## Asynchronous Email Sending\r\n\r\nIf you are sending slightly different emails to a large number of people, it might take quite a while to process. By default, Django will process this all synchronously. For asynchronous support, we recommend django-celery-email. It is very straightfoward to setup and integrate: https://github.com/pmclanahan/django-celery-email\r\n\r\n\r\n## herald.contrib.auth\r\n\r\nDjango has built-in support for sending password reset emails. If you would like to send those emails using herald, you can use the notification class in herald.contrib.auth.\r\n\r\nFirst, add `herald.contrib.auth` to `INSTALLED_APPS` (in addition to `herald`).\r\n\r\nSecond, use the `HeraldPasswordResetForm` in place of django's built in `PasswordResetForm`. This step is entirely dependant on your project structure, but it essentially just involves changing the form class on the password reset view in some way:\r\n\r\n```python\r\n# you may simply just need to override the password reset url like so:\r\nurl(r'^password_reset/$', password_reset, name='password_reset', {'password_reset_form': HeraldPasswordResetForm}),\r\n\r\n# of if you are using something like django-authtools:\r\nurl(r'^password_reset/$', PasswordResetView.as_view(form_class=HeraldPasswordResetForm), name='password_reset'),\r\n\r\n# or you may have a customized version of the password reset view:\r\nclass MyPasswordResetView(FormView):\r\n    form_class = HeraldPasswordResetForm  # change the form class here\r\n\r\n# or, you may have a custom password reset form already. In that case, you will want to extend from the HeraldPasswordResetForm:\r\nclass MyPasswordResetForm(HeraldPasswordResetForm):\r\n    ...\r\n\r\n# alternatively, you could even just send the notification wherever you wish, seperate from the form:\r\nPasswordResetEmail(some_user).send()\r\n```\r\n\r\nThird, you may want to customize the templates for the email. By default, herald will use the `registration/password_reset_email.html` that is provided by django for both the html and text versions of the email. But you can simply override `herald/html/password_reset.html` and/or `herald/text/password_reset.txt` to suit your needs.\r\n\r\n## User Disabled Notifications\r\n\r\nIf you want to disable certain notifications per user, add a record to the UserNotification table and\r\nadd notifications to the disabled_notifications many to many table.\r\n\r\nFor example:\r\n\r\n```python\r\nuser = User.objects.get(id=user.id)\r\n\r\nnotification = Notification.objects.get(notification_class=MyNotification.get_class_path())\r\n\r\n# disable the notification\r\nuser.usernotification.disabled_notifications.add(notification)\r\n```\r\n\r\nBy default, notifications can be disabled.  You can put can_disable = False in your notification class and the system will\r\npopulate the database with this default.  Your Notification class can also override the verbose_name by setting it in your\r\ninherited Notification class.  Like this:\r\n\r\n```python\r\nclass MyNotification(EmailNotification):\r\n    can_disable = False\r\n    verbose_name = \"My Required Notification\"\r\n```\r\n\r\n## Email Attachments\r\n\r\nTo send attachments, assign a list of attachments to the attachments attribute of your EmailNotification instance, or override the get_attachments() method.\r\n\r\nEach attachment in the list can be one of the following:\r\n\r\n1. A tuple which consists of the filename, the raw attachment data, and the mimetype. It is up to you to get the attachment data. Like this:\r\n\r\n```python\r\nraw_data = get_pdf_data()\r\n\r\nemail.attachments = [\r\n    ('Report.pdf', raw_data, 'application/pdf'),\r\n    ('report.txt', 'text version of report', 'text/plain')\r\n]\r\nemail.send()\r\n```\r\n\r\n2. A MIMEBase object. See the documentation for attachments under EmailMessage Objects/attachments in the Django documentation.\r\n\r\n3. A django `File` object.\r\n\r\n### Inline Attachments\r\n\r\nSometimes you want to embed an image directly into the email content.  Do that by using a MIMEImage assigning a content id header to a MIMEImage, like this:\r\n\r\n```python\r\nemail = WelcomeEmail(user)\r\nim = get_thumbnail(image_file.name, '600x600', quality=95)\r\nmy_image = MIMEImage(im.read()) # MIMEImage inherits from MIMEBase\r\nmy_image.add_header('Content-ID', '<{}>'.format(image_file.name))\r\n```\r\n\r\nYou can refer to these images in your html email templates using the Content ID (cid) like this:\r\n\r\n```html\r\n<img src=\"cid:{{image_file.name}}\" />\r\n```\r\n\r\nYou would of course need to add the \"image_file\" to your template context in the example above.  You can also accomplish this using file operations.  In this example we overrode the get_attachments method of an EmailNotification.\r\n\r\n```python\r\nclass MyNotification(EmailNotification):\r\n    context = {'hello': 'world'}\r\n    template_name = 'welcome_email'\r\n    to_emails = ['somebody@example.com']\r\n    subject = \"My email test\"\r\n\r\n    def get_attachments(self):\r\n        fp = open('python.jpeg', 'rb')\r\n        img = MIMEImage(fp.read())\r\n        img.add_header('Content-ID', '<{}>'.format('python.jpeg'))\r\n        return [\r\n            img,\r\n        ]\r\n```\r\n\r\nAnd in your template you would refer to it like this, and you would not need to add anything to the context:\r\n\r\n```html\r\n    <img src=\"cid:python.jpeg\" />\r\n```\r\n\r\n### HTML2Text Support\r\n\r\nDjango Herald can auto convert your HTML emails to plain text.  Any email without a plain text version\r\nwill be auto converted if you enable this feature.\r\n\r\n```\r\n# Install html2text\r\npip install django-herald[html2text]\r\n```\r\n\r\nIn your settings.py file:\r\n\r\n```\r\nHERALD_HTML2TEXT_ENABLED = True\r\n```\r\n\r\nYou can customize the output of HTML2Text by setting a configuration dictionary. See \r\n[HTML2Text Configuration](https://github.com/Alir3z4/html2text/blob/master/docs/usage.md) for options\r\n\r\n```\r\nHERALD_HTML2TEXT_CONFIG = {\r\n    # Key / value configuration of html2text \r\n    'ignore_images': True  # Ignores images in conversion\r\n}\r\n```\r\n\r\n### Twilio\r\n\r\n```\r\n# Install twilio\r\npip install django-herald[twilio]\r\n```\r\n\r\nYou can retrieve these values on [Twilio Console](https://twilio.com/console). Once you have retrieve the necessary ids, you can place those to your `settings.py`.\r\n\r\nFor reference, Twilio has some great tutorials for python.\r\n[Twilio Python Tutorial](https://www.twilio.com/docs/sms/quickstart/python)\r\n\r\n```\r\n# Twilio configurations\r\n# values taken from `twilio console`\r\nTWILIO_ACCOUNT_SID = \"your_account_sid\"\r\nTWILIO_AUTH_TOKEN = \"your_auth_token\"\r\nTWILIO_DEFAULT_FROM_NUMBER = \"+1234567890\"\r\n\r\n```\r\n\r\n### Other MIME attachments\r\n\r\nYou can also attach any MIMEBase objects as regular attachments, but you must add a content-disposition header, or they will be inaccessible:\r\n\r\n```python\r\nmy_image.add_header('Content-Disposition', 'attachment; filename=\"python.jpg\"')\r\n```\r\n\r\nAttachments can cause your database to become quite large, so you should be sure to run the management commands to purge the database of old messages.\r\n\r\n# Running Tests\r\n\r\n```bash\r\npython runtests.py\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Django library for separating the message content from transmission method",
    "version": "0.2.1.21",
    "project_urls": {
        "Download": "https://github.com/vvkvivekl/omic-django-herald/tarball/0.2.1.21",
        "Homepage": "https://github.com/vvkvivekl/omic-django-herald/"
    },
    "split_keywords": [
        "django",
        "notifications",
        "messaging"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "63178d938369bda17f64298171ab2a4a7977c4c8f2c04c83ed1284dbb0da2dba",
                "md5": "f5945dd31e5b73355f5469d89adcd5e9",
                "sha256": "f0d79c8cbc569e8910977364b665b6180bebb8a4812d177cd64f507dee087b3c"
            },
            "downloads": -1,
            "filename": "omic_django_herald-0.2.1.21-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f5945dd31e5b73355f5469d89adcd5e9",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 29212,
            "upload_time": "2023-07-31T03:01:31",
            "upload_time_iso_8601": "2023-07-31T03:01:31.241810Z",
            "url": "https://files.pythonhosted.org/packages/63/17/8d938369bda17f64298171ab2a4a7977c4c8f2c04c83ed1284dbb0da2dba/omic_django_herald-0.2.1.21-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "808787580869b171d01f829079b201726a2985fa79d108e3c4e2abbe95b9fe57",
                "md5": "6b3eac0ac139b606f75b367a4ba0939d",
                "sha256": "78e67aff59a05206497e69b4cf7f61e2688cf9abc8649b45fcc77d66c2a099fd"
            },
            "downloads": -1,
            "filename": "omic-django-herald-0.2.1.21.tar.gz",
            "has_sig": false,
            "md5_digest": "6b3eac0ac139b606f75b367a4ba0939d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 30123,
            "upload_time": "2023-07-31T03:01:33",
            "upload_time_iso_8601": "2023-07-31T03:01:33.393582Z",
            "url": "https://files.pythonhosted.org/packages/80/87/87580869b171d01f829079b201726a2985fa79d108e3c4e2abbe95b9fe57/omic-django-herald-0.2.1.21.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-31 03:01:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vvkvivekl",
    "github_project": "omic-django-herald",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "requirements": [
        {
            "name": "six",
            "specs": []
        },
        {
            "name": "mock",
            "specs": []
        },
        {
            "name": "jsonpickle",
            "specs": []
        },
        {
            "name": "twilio",
            "specs": []
        },
        {
            "name": "coveralls",
            "specs": []
        },
        {
            "name": "pytz",
            "specs": []
        },
        {
            "name": "html2text",
            "specs": [
                [
                    "==",
                    "2018.1.9"
                ]
            ]
        }
    ],
    "tox": true,
    "lcname": "omic-django-herald"
}
        
Elapsed time: 0.09467s