The Communication Doctype is a cornerstone of Frappe's interaction tracking capabilities, designed to log and manage various forms of communication, with a strong emphasis on email. It also supports other mediums like Chat, Phone, SMS, and system events.
- To serve as a central repository for all communications sent from or received into the Frappe system.
- To link communications to relevant documents (e.g., Leads, Sales Orders, Issues) and Contacts.
- To facilitate email integration, including sending, receiving, replying, forwarding, and tracking email status.
- To provide a timeline view of interactions related to specific documents.
- To support features like automated email responses, email templates, and scheduling emails.
communication.json: Defines the schema (fields, properties, permissions).communication.py: Contains the main server-side Python controller logic.communication.js: Handles client-side JavaScript for the Communication form, providing an email client-like interface.email.py: Likely contains specialized functions for email processing, validation, and interaction with email services (used bycommunication.py).mixins.py: Probably contains reusable Python classes or methods (mixins) for email functionalities, shared withcommunication.py.README.md: Provides a brief overview.communication_list.js: Customizes the list view.test_communication.py: Unit tests.
This JSON file outlines the extensive structure for Communication entries.
email_append_to: 1: Enables direct creation/linking of Communications from incoming emails.sender_field: "sender",subject_field: "subject": Designated fields for email integration.- Key Fields:
subject(Small Text, Required): The subject line of the communication.communication_medium(Select): Type like "Email", "Chat", "Phone", "SMS", "Event", "Meeting", "Visit", "Other".content(Text Editor): The main body/message of the communication.sender(Data, Email): Sender's email address.recipients,cc,bcc(Code, Email): Email recipient lists.phone_no(Data): For phone/SMS.status(Select): "Open", "Replied", "Closed", "Linked".sent_or_received(Select, Required): Indicates if the communication was "Sent" or "Received".communication_date(Datetime): Timestamp of the communication.reference_doctype&reference_name(Dynamic Link): Links the communication to a primary Frappe document.timeline_links(Table, child: "Communication Link"): Allows linking a single communication to multiple documents for comprehensive timeline views.email_account(Link to Email Account): The Frappe Email Account used.in_reply_to(Link to Communication): Links to a previous communication in a thread.delivery_status(Select, Hidden): Tracks detailed email delivery events (Sent, Bounced, Opened, Clicked, etc.).email_template(Link to Email Template): If an email template was used.send_after(Datetime): For scheduling future email dispatches.- Email inbox fields:
message_id,uid(IMAP UID),imap_folder,email_status("Open", "Spam", "Trash").
- Permissions:
- Complex, with different access levels for "System Manager", "Inbox User", and "All" (based on ownership). Permissions are also defined at different
permlevels, suggesting field-level security.
- Complex, with different access levels for "System Manager", "Inbox User", and "All" (based on ownership). Permissions are also defined at different
- Other Properties:
track_changes: 1,track_seen: 1.row_format: "Compressed" for a compact list view.
The Python controller is rich with features for managing communications.
Communication(Document, CommunicationEmailMixin)Class:- Inherits from
CommunicationEmailMixinfor shared email functionalities. onload(): Creates "Email Flag Queue" entries for received emails to mark them as read on the IMAP server.validate(): Extensive validation including:- Setting defaults for
user,subject,sent_or_received. - Calling
validate_email()(fromcommunication/email.py). - Parsing email content/recipients for automatic
timeline_linksbased ondoctype+docname@domainpatterns. - Linking to
Contactrecords. - Setting sender's full name.
- Marking emails as spam if sender is on a spam list.
- Setting defaults for
after_insert(): Updates status of replied-to communications; notifies changes for real-time updates.set_signature_in_email_content(): Appends user or default outgoing email signatures.on_update(): Updates the_commentscache on the parent document and callsupdate_parent_document_on_communication()(or a custom hook on the parent) to update fields like status or response times.notify_change(): Publishes real-time events for UI updates on related documents.set_delivery_status(): Updates thedelivery_statusfield based on "Email Queue" records.- Manages
timeline_links(add, get, remove, deduplicate).
- Inherits from
- Global Functions:
has_permission(): Custom permission logic, allowing read access if the user can read the referenced document.get_permission_query_conditions_for_communication(): Tailors list view visibility based on user roles and their associated "User Email" accounts.- Email parsing utilities (
get_contacts,get_emails,parse_email,get_email_without_link). update_parent_document_on_communication(): Updates status and response time metrics (e.g.,first_response_time,avg_response_time) on linked parent documents like "Issue" or "Support Ticket".
Provides a feature-rich interface, especially for emails.
onload(frm): Sanitizes HTML content and sets filters forreference_doctypeselection.refresh(frm):- Sets the
contentfield to read-only. - Adds numerous custom buttons for email actions if the communication is a received email:
- "Reply", "Reply All", "Forward": Opens the
frappe.views.CommunicationComposer. - "Mark as Unread/Read", "Mark as Spam", "Move To Trash": Trigger server-side actions, often via an email flag queue or inbox management methods.
- "Move": Opens a dialog to move the email to another configured Email Account.
- "Contact" (Create): To quickly create a Contact from sender details.
- "Reply", "Reply All", "Forward": Opens the
- Adds "Close"/"Reopen" buttons for managing communication status.
- Adds a "Relink" button to change the
reference_doctypeandreference_name.
- Sets the
- Dialog Handlers (
show_relink_dialog,show_move_dialog): Manage UI for relinking and moving emails. - Action Handlers (
mark_as_read_unread,mark_as_closed_open,reply,reply_all,forward_mail,add_to_contact,mark_as_spam,move_to_trash): Implement the logic for the custom buttons, often by calling server-side methods or opening the composer. get_mail_args(frm): A helper to prepare data for theCommunicationComposer.
- These files (not fully analyzed here) would contain more specialized Python code for:
email.py: Email validation, parsing, interacting with SMTP/IMAP servers (possibly viaEmailAccountDoctype's logic), handling email headers, content types, and attachments.mixins.py: Reusable methods for email functionalities that might be shared across different Doctypes or modules that deal with emails.
- Confirms that "Communication" tracks emails/messages.
- Highlights that
receive.py(likelyfrappe.email.receive) handles incoming mail and creates Communication documents.
- Sending Emails: Users can compose and send emails from within Frappe (e.g., from a Sales Order, clicking "Email"). This creates a "Sent" Communication.
- Receiving Emails: Frappe polls configured Email Accounts. Incoming emails are fetched (by
frappe.email.receive) and new "Received" Communication documents are created. - Document Timeline: Communications linked to a document (e.g., an Issue) appear in its timeline, providing a history of all interactions.
- Automated Notifications: System notifications (e.g., workflow approvals, alerts) can be sent as emails and logged as Communications of type "Automated Message".
- Support/CRM: Heavily used in modules like Support (for Issues) and CRM (for Leads, Opportunities) to track all customer interactions.
- Scheduled Emails: Emails can be scheduled to be sent later using the
send_afterfield.
The Communication Doctype is a critical hub for managing interactions, providing a unified record and interface for emails and other communication channels within the Frappe ecosystem.