BOB Docs
APITutorials

Mailing

Mailing is a crucial part of any project, especially for startups. We designed it to be highly flexible yet ready to use out of the box. Predefined email templates ensure you gain valuable feedback and remain proactive with your users. Emails are sent in the following situations:

  • New User Creation - Welcome email to the user.
  • New Purchase - Confirmation and details of the purchase.
  • Invoice Data - Sends the invoice and additional purchase details.
  • Subscription Cancellation - Requests feedback on why the subscription was canceled.
  • Invitation - Invitation to join an organization.
  • Validation Email - Sent when validation for new users is required.
  • Password Reset - Sent when a user requests a password reset.

The mailer app is responsible for managing all email functionalities. Emails are sent asynchronously using Celery, so make sure to run the Celery worker before starting.

Templates

Email templates can be easily customized by editing files in the mailer/templates directory. Each email includes both .txt and .html versions to ensure proper formatting, even for clients that block HTML.

Explore awesome email template ideas and learn how to implement them easily in the guidebook.

Each template is automatically populated with “common” data, which can be prepared using a dedicated method in the MailerService:

def _update_context_with_common_data(context: dict):
    """
    Updates the provided context with common data shared across all emails.
 
    Args:
        context (dict): Initial context to update.
 
    Returns:
        dict: Updated context with common data.
    """
    context.update({
        "authors": settings.AUTHORS_SIGNATURE,
        "business_name": settings.BUSINESS_NAME
    })
    return context

Sending Emails

You can use your own SMTP server or integrate with Mailgun for sending emails. Ensure the DEFAULT_EMAIL_PROVIDER environment variable is set correctly.

After setting the email provider, test the email sending functionality using the following Django command:

python manage.py sendtestemail <receiver_email_address> --attachment_path <path_to_attachment>

SMTP

To configure SMTP, set smtp as the value of the DEFAULT_EMAIL_PROVIDER variable. Additionally, provide the following SMTP client details in your environment variables file:

  • SMTP_SERVER
  • SMTP_USERNAME
  • SMTP_PORT
  • SMTP_PASSWORD

Mailgun

To use Mailgun, set mailgun as the value of the DEFAULT_EMAIL_PROVIDER variable and provide the following details for integration:

  • MAILGUN_API_KEY - Obtain your key by creating an account in Mailgun and navigating to API Security → Add New Key.
  • MAILGUN_POST_URL - Construct the URL as follows: https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages Replace YOUR_DOMAIN_NAME with your actual domain name.

On this page