# Django dynamic SMTP

Configure email configuration in the admin.

## Usage

1. Install with `pip install django-dynamic-smtp`

2. Add `dynamic_smtp` and some dependencies to `INSTALLED_APPS`:

```python
INSTALLED_APPS = [
    ...,
    "django_object_actions",
    "tinymce",
    "dynamic_smtp",
]
```

3. Configure your email backend:

```python
EMAIL_BACKEND = (
    "django.core.mail.backends.console.EmailBackend"
    if DEBUG
    else "dynamic_smtp.email.DynamicSMPTEmailBackend"
)
```

4. Migrate: `./manage.py migrate`
5. Configure `tinymce`. Example:

```python
TINYMCE_JS_URL = "https://cdnjs.cloudflare.com/ajax/libs/tinymce/7.0.1/tinymce.min.js"
TINYMCE_DEFAULT_CONFIG = {
    "theme": "silver",
    "height": 600,
    "width": 700,
    "resize": "both",
    "plugins": "advlist,autolink,lists,link,image,charmap,print,preview,anchor,"
    "searchreplace,visualblocks,code,fullscreen,insertdatetime,media,table,paste,"
    "help,wordcount",
    "license_key": "gpl",
}
```

See [django-tinymce's documentation](https://django-tinymce.readthedocs.io/en/latest/)
for more options.

6. Access you admin and configure your SMTP settings

### Customize model admin

1. Don't let our app register the default model admin:

```python
# settings.py

...
DYNAMIC_SMPT_REGISTER_ADMIN = False
DYNAMIC_SMPT_REGISTER_MODEL = False
```

2. Register your custom admin
```python
# myapp/models.py

from dynamic_smtp.models import AbstractEmailConfiguration

class EmailConfiguration(AbstractEmailConfiguration):
    pass

```

```python
# myapp/admin.py

from django.contrib import admin
from dynamic_smtp.models import AbstractEmailConfiguration

from .models import Emailconfiguration


@admin.register(EmailConfiguration)
class CustomModelAdmin(EmailConfigurationAdmin):
    class Media:
        css = {"all": ["myapp/style.css"]}

```

## Dependencies

This package needs quite a few dependencies, considering its simplicity.

- `Django`
- `beautifulsoup4` and `lxml`: prepare text version of HTML emails
- `django-object-actions`: Button for email test
- `django-tinymce`: Button for email test
- `django-solo`: Use singleton model

## Contributing

All contributions are welcome! To setup you environment:

1. `pip install -r dev.requirements.txt`
2. `pre-commit install`
