Sending Emails From Haptik Platform
- Getting Started
- Bot Building
- Smart Agent Chat
- Conversation Design
-
Developer Guides
Code Step Integration Static Step Integration Shopify Integration SETU Integration Exotel Integration CIBIL integration Freshdesk KMS Integration PayU Integration Zendesk Guide Integration Twilio Integration Razorpay Integration LeadSquared Integration USU(Unymira) Integration Helo(VivaConnect) Integration Salesforce KMS Integration Stripe Integration PayPal Integration CleverTap Integration Fynd Integration HubSpot Integration Magento Integration WooCommerce Integration Microsoft Dynamics 365 Integration
- Deployment
- External Agent Tool Setup
- Analytics & Reporting
- Notifications
- Commerce Plus
- Troubleshooting Guides
- Release Notes
Table of Contents
Overview
Our platform includes built-in support for sending emails. This feature enables sending transactional or notification-based emails using a flexible, programmatic interface.
🔧 Use Cases
- User registration confirmations
- Password reset links
- System alerts or status updates
-
Custom email notifications
🧱 Prerequisites
Ensure the following settings are configure:( this is configured already in Haptik)
# settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = '<your-smtp-host>'
EMAIL_PORT = 587 # or 465 for SSL
EMAIL_USE_TLS = True # or EMAIL_USE_SSL = True
EMAIL_HOST_USER = '<your-email-address>'
EMAIL_HOST_PASSWORD = '<your-email-password>'
DEFAULT_FROM_EMAIL = ‘<your-default-sender>’
✉️ Sending Email with EmailMessage in Haptik Platfrom
The platform utilizes Django's EmailMessage class to send out emails. Here's how to use it:
from django.core.mail import EmailMessage
def send_custom_email(subject, body, to_emails, from_email=None, attachments=None):
email = EmailMessage(
subject=subject,
body=body,
from_email=from_email or DEFAULT_FROM_EMAIL,
to=to_emails,
)
# Optional: Attach files
if attachments:
for attachment in attachments:
email.attach_file(attachment)
# Send the email
email.send(fail_silently=False)
✅ Example
send_custom_email(
subject="Welcome to Our Platform!",
body="Hi there,\n\nThank you for signing up. We're glad to have you!",
to_emails=["user@example.com"]
)
📂 Attachments Support
You can attach files like PDFs, CSVs, images, etc., using the attach_file() method:
python
CopyEdit
email.attach_file('/path/to/file.pdf')
🔁 HTML Emails (Optional Enhancement)
For HTML content, use Django’s EmailMultiAlternatives:
python
CopyEdit
from django.core.mail import EmailMultiAlternatives
email = EmailMultiAlternatives(
subject="HTML Email Example",
body="This is the fallback plain text version.",
from_email=DEFAULT_FROM_EMAIL,
to=["user@example.com"],
)
html_content = "<p>This is an <strong>HTML</strong> message.</p>"
email.attach_alternative(html_content, "text/html")
email.send()
📌 Notes
- Ensure the SMTP credentials are correct and have permission to send emails.
- Monitor for delivery failures or SMTP issues.
- Use environment variables to store sensitive email credentials securely.
🛡️ Security Tip
Avoid hardcoding sensitive information like passwords. Use environment variables or a secrets manager.