@frappe.whitelist()
def make(doctype=None, name=None, content=None, subject=None, sent_or_received=u'Sent', sender=None, sender_full_name=None, recipients=None, communication_medium=u'Email', send_email=False, print_html=None, print_format=None, attachments=u'[]', send_me_a_copy=False, cc=None, flags=None, read_receipt=None):
 is_error_report = ((doctype == u'User') and (name == frappe.session.user) and (subject == u'Error Report'))
 send_me_a_copy = cint(send_me_a_copy)
 if (doctype and name and (not is_error_report) and (not frappe.has_permission(doctype, u'email', name)) and (not (flags or {}).get(u'ignore_doctype_permissions'))):
  raise frappe.PermissionError(u'You are not allowed to send emails related to: {doctype} {name}'.format(doctype=doctype, name=name))
 if (not sender):
  sender = get_formatted_email(frappe.session.user)
 comm = frappe.get_doc({u'doctype': u'Communication', u'subject': subject, u'content': content, u'sender': sender, u'sender_full_name': sender_full_name, u'recipients': recipients, u'cc': (cc or None), u'communication_medium': communication_medium, u'sent_or_received': sent_or_received, u'reference_doctype': doctype, u'reference_name': name, u'message_id': get_message_id().strip(u' <>'), u'read_receipt': read_receipt})
 comm.insert(ignore_permissions=True)
 if (not doctype):
  comm.db_set(dict(reference_doctype=u'Communication', reference_name=comm.name))
 if isinstance(attachments, basestring):
  attachments = json.loads(attachments)
 if attachments:
  add_attachments(comm.name, attachments)
 frappe.db.commit()
 if cint(send_email):
  comm.send(print_html, print_format, attachments, send_me_a_copy=send_me_a_copy)
 return {u'name': comm.name, u'emails_not_sent_to': (u', '.join(comm.emails_not_sent_to) if hasattr(comm, u'emails_not_sent_to') else None)}

@ frappe . whitelist ( ) def make ( doctype = None , name = None , content = None , subject = None , sent_or_received = u'Sent' , sender = None , sender_full_name = None , recipients = None , communication_medium = u'Email' , send_email = False , print_html = None , print_format = None , attachments = u'[]' , send_me_a_copy = False , cc = None , flags = None , read_receipt = None ) : is_error_report = ( ( doctype == u'User' ) and ( name == frappe . session . user ) and ( subject == u'Error Report' ) ) send_me_a_copy = cint ( send_me_a_copy ) if ( doctype and name and ( not is_error_report ) and ( not frappe . has_permission ( doctype , u'email' , name ) ) and ( not ( flags or { } ) . get ( u'ignore_doctype_permissions' ) ) ) : raise frappe . PermissionError ( u'You are not allowed to send emails related to: {doctype} {name}' . format ( doctype = doctype , name = name ) ) if ( not sender ) : sender = get_formatted_email ( frappe . session . user ) comm = frappe . get_doc ( { u'doctype' : u'Communication' , u'subject' : subject , u'content' : content , u'sender' : sender , u'sender_full_name' : sender_full_name , u'recipients' : recipients , u'cc' : ( cc or None ) , u'communication_medium' : communication_medium , u'sent_or_received' : sent_or_received , u'reference_doctype' : doctype , u'reference_name' : name , u'message_id' : get_message_id ( ) . strip ( u' <>' ) , u'read_receipt' : read_receipt } ) comm . insert ( ignore_permissions = True ) if ( not doctype ) : comm . db_set ( dict ( reference_doctype = u'Communication' , reference_name = comm . name ) ) if isinstance ( attachments , basestring ) : attachments = json . loads ( attachments ) if attachments : add_attachments ( comm . name , attachments ) frappe . db . commit ( ) if cint ( send_email ) : comm . send ( print_html , print_format , attachments , send_me_a_copy = send_me_a_copy ) return { u'name' : comm . name , u'emails_not_sent_to' : ( u', ' . join ( comm . emails_not_sent_to ) if hasattr ( comm , u'emails_not_sent_to' ) else None ) }
run make .