Skip to main content

A Django app for configuring mail

Project description

Custom Mailer

You can customize your emails using templates using variables

Add 'mail_configuration' in your installed app after installing this package

INSTALLED_APPS = [
    ...
    'mail_configuration',
    ... 
]

Then migrate to apply related changes for your project

python manage.py migrate

Configure your email templates and send emails

Go to admin panel and configure your email templates on the app name 'mail_configuration', email template format is provided below

Sample OTP payload

payload = {
    "mail_service": "smtp",
    "email_from": "solutionizeit.x@gmail.com",
    "recipient_list": "jasirmj@gmail.com",
    "subject": "Test Mail",
    "html_template": "OTP",
    "variables":{
        "otp":"0786",
        "content":"Hi your otp is",
        "brand": "SolutionizeIT"
    }
}

sendMail(**payload)

Sample HTML OTP Template

<div style="font-family: Helvetica,Arial,sans-serif;min-width:1000px;overflow:auto;line-height:2">
    <div style="margin:50px auto;width:70%;padding:20px 0">
        <div style="border-bottom:1px solid #eee">
            <a href="" style="font-size:2.4em;color: #00466a;text-decoration:none;font-weight:600">{{brand}}</a>
        </div>
        <p style="font-size:1.1em">Hi,</p>
        <p>{{content}}</p>
        <h1
            style="background: #00466a;margin: 0 auto;width: max-content;padding: 0 10px;color: #fff;border-radius: 4px;">
            {{otp}}</h1>
        <p style="font-size:0.9em;">Regards,<br />{{brand}}</p>
        <hr style="border:none;border-top:1px solid #eee" />
        <div style="float:right;padding:8px 0;color:#aaa;font-size:0.8em;line-height:1;font-weight:300">
            <p>{{brand}}</p>
            <!-- <p>1600 Amphitheatre Parkway</p>
            <p>California</p> -->
        </div>
    </div>
</div>

##@ Invoice Sample Payload:

payload = {
    "mail_service": "smtp",
    "email_from": "solutionizeit.x@gmail.com",
    "recipient_list": "jasirmj@gmail.com",
    "subject": "Test Mail",
    "html_template": "invoice",
    "variables": {
        "company_name": "Your Company",
        "address_line_one": "XYZ 2nd Floor",
        "address_line_two": "123 Street, Washington",
        "customer_name": "John Doe",
        "email": "Email: johndoe@gmail.com",
        "phone": "Phone: 555 555 555 555",
        "invoice_id": "1002658",
        "invoice_date": "2024-08-30",
        "due_date": "2024-08-30",
        "invoice_items": [
            {"name": "Product 1", "description": "Description of product 1",
                "quantity": 2, "price": "$20", "total": 123},
            {"name": "Product 2", "description": "Description of product 2",
                "quantity": 1, "price": "$15", "total": 123},
            # Add more items as needed
        ],
        "discount": "10",
        "total_amount": "1055",
    }
}

HTML Invoice Template

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Invoice</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f8f8f8;
        }
        .invoice-box {
            max-width: 800px;
            margin: auto;
            padding: 30px;
            border: 1px solid #eee;
            background-color: #fff;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.15);
        }
        .invoice-header {
            width: 100%;
            margin-bottom: 20px;
        }
        .invoice-header td {
            vertical-align: top;
        }
        .invoice-header .company-details {
            text-align: right;
        }
        .invoice-header .company-details h2 {
            margin: 0;
            font-size: 18px;
        }
        .invoice-header .company-details p {
            margin: 2px 0;
        }
        .invoice-details {
            margin-bottom: 20px;
        }
        .invoice-details table {
            width: 100%;
            border-collapse: collapse;
        }
        .invoice-details table th, .invoice-details table td {
            padding: 10px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }
        .invoice-details table th {
            background-color: #f2f2f2;
        }
        .invoice-total {
            text-align: right;
            margin-top: 20px;
        }
        .invoice-total h3 {
            margin: 0;
            font-size: 18px;
        }
    </style>
</head>
<body>
    <div class="invoice-box">
        <table class="invoice-header">
            <tr>
                <td>
                    <h1>Invoice</h1>
                </td>
                <td class="company-details">
                    <h2>{{company_name}}</h2>
                    <p>{{address_line_one}}</p>
                    <p>{{address_line_two}}</p>
                    <p>{{email}}</p>
                    <p>{{phone}}</p>
                </td>
            </tr>
        </table>
        <div class="invoice-details">
            <table>
                <tr>
                    <th>Invoice #:</th>
                    <td>{{invoice_id}}</td>
                    <th>Invoice Date:</th>
                    <td>{{invoice_date}}</td>
                </tr>
                <tr>
                    <th>Client Name:</th>
                    <td>{{customer_name}}</td>
                    <th>Due Date:</th>
                    <td>{{due_date}}</td>
                </tr>
            </table>
        </div>
        <div class="invoice-details">
            <table>
                <tr>
                    <th>Description</th>
                    <th>Quantity</th>
                    <th>Unit Price</th>
                    <th>Total</th>
                </tr>
              {% for item in invoice_items %}
                <tr>
                    <td>{{item.name}}</td>
                    <td>{{item.quantity}}</td>
                    <td>{{item.price}}</td>
                    <td>{{item.total}}</td>
                </tr>
              {% endfor %}
                <tr>
                    <th colspan="3" style="text-align: right;">Discount:</th>
                    <td>{{discount}}</td>
                </tr>
                <tr>
                    <th colspan="3" style="text-align: right;">Total:</th>
                    <td>{{total_amount}}</td>
                </tr>
            </table>
        </div>
        <div class="invoice-total">
            <h3>{{total_amount}}</h3>
        </div>
    </div>
</body>
</html>

Usage

from mail_configuration.views import sit_send_mail

sit_send_mail(**payload)

SMTP Gmail Configuration

Go to your Gmail settings and enable 'Less secure app access' After that, you can use your credentials to send emails

Settings.py

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'YOUR_LESS_SECURE_ENABLED_GMAIL'
EMAIL_HOST_PASSWORD = 'YOUR_APP_PASSWORD'

Mailing Service Config

Name: smtp
Email backend: django.core.mail.backends.smtp.EmailBackend
Email host: smtp.gmail.com
Email port: 587
Email use tls: Yes
Email host user: YOUR_LESS_SECURE_ENABLED_GMAIL
Email host password: YOUR_APP_PASSWORD

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

mail_configuration-1.0.2.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mail_configuration-1.0.2-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file mail_configuration-1.0.2.tar.gz.

File metadata

  • Download URL: mail_configuration-1.0.2.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for mail_configuration-1.0.2.tar.gz
Algorithm Hash digest
SHA256 6617a33e96474d74586f8822683e4a6cf6433ac96071f95a8672c00879ea1a0f
MD5 fe0d6f0f66bc56f5bfe5616544d4efa1
BLAKE2b-256 13981657268222c6ea5912de182dedaddb994bbba3fb25b76b3fd9cf6e302e3c

See more details on using hashes here.

File details

Details for the file mail_configuration-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mail_configuration-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5907764b07e17e8d1bdffce87f47f5fc8d1523f6163ec3de32176ee704887d6c
MD5 2ceb73ef4387386892e4e1d76f6921cb
BLAKE2b-256 39c13eb4884e3515d3fd1520342832e8dec848170be4d620ad72080b6ee1f84f

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