Example #1
0
def make(doctype=None, name=None, content=None, subject=None, sent_or_received = "Sent",
	sender=None, recipients=None, communication_medium="Email", send_email=False,
	print_html=None, print_format=None, attachments='[]', ignore_doctype_permissions=False,
	send_me_a_copy=False,ref_no=None):


	if not sender and frappe.session.user != "Administrator":
		sender = frappe.db.get_value("Email Config",{"default_account":1,"user":frappe.session.user},"email_id")

	if not validated_email_addrs(recipients):
		return {"not_valid":1}

	comm = frappe.get_doc({
		"doctype":"Outbox",
		"subject": subject,
		"content": content,
		"sender": sender,
		"recipients": recipients,
	})
	comm.insert(ignore_permissions=True)

	attachments = get_attachments(ref_no)
	for attachment in attachments:
		file_data = {}
		furl = "/files/%s"%attachment["file_name"]
		file_data.update({
			"doctype": "File Data",
			"attached_to_doctype":"Outbox",
			"attached_to_name":comm.name,
			"file_url":furl,
			"file_name":attachment["file_name"]
			
		})
		f = frappe.get_doc(file_data)
		f.flags.ignore_permissions = True
		f.insert();

	recipients = get_recipients(recipients)

	attachments = [attachment["file_name"] for attachment in attachments]
	attachments = prepare_attachments(attachments)
	
	mailbox.sendmail(
		recipients=recipients,
		sender=sender,
		subject=subject,
		content=content,
		attachments=attachments
	)

	return {
		"name": comm.name,
		"recipients": ", ".join(recipients) if recipients else None
	}
Example #2
0
def make(doctype=None,
         name=None,
         content=None,
         subject=None,
         sent_or_received="Sent",
         sender=None,
         recipients=None,
         communication_medium="Email",
         send_email=False,
         print_html=None,
         print_format=None,
         attachments='[]',
         ignore_doctype_permissions=False,
         send_me_a_copy=False,
         email_account=None,
         doc=None,
         forward_or_reply=None):

    if not sender and frappe.session.user != "Administrator":
        sender = frappe.db.get_value("Email Config", {"name": email_account},
                                     "email_id")
    import json
    doc = json.loads(doc)

    comm = frappe.get_doc({
        "doctype": "Outbox",
        "subject": subject,
        "content": content,
        "tag": doc.get('tag') or "",
        "customer": doc.get("customer") or "",
        "supplier": doc.get("supplier") or "",
        "sender": sender,
        "recipients": recipients,
    })
    comm.insert(ignore_permissions=True)

    #attachments = get_attachments(doctype,name)
    attachments = prepare_attachments(attachments)
    for attachment in attachments:
        file_data = {}
        furl = "/files/%s" % attachment["fname"]
        file_data.update({
            "doctype": "File Data",
            "attached_to_doctype": "Outbox",
            "attached_to_name": comm.name,
            "file_url": furl,
            "file_name": attachment["fname"]
        })
        f = frappe.get_doc(file_data)
        f.flags.ignore_permissions = True
        f.insert()

    recipients = get_recipients(recipients)
    attachments = prepare_attachments(attachments)

    mailbox.sendmail(
        recipients=recipients,
        sender=sender,
        subject=subject,
        content=content,
        attachments=attachments,
    )

    doc = frappe.get_doc("Inbox", name)
    if forward_or_reply == 'reply':
        doc.tag = 'Responded'
    elif forward_or_reply == 'forward':
        doc.tag = 'Forwarded to Other User'
    doc.save(ignore_permissions=True)

    return {
        "name": comm.name,
        "recipients": ", ".join(recipients) if recipients else None
    }
Example #3
0
def make(doctype=None, name=None, content=None, subject=None, sent_or_received = "Sent",
	sender=None, recipients=None, communication_medium="Email", send_email=False,
	print_html=None, print_format=None, attachments='[]', ignore_doctype_permissions=False,
	send_me_a_copy=False,email_account=None,doc=None,forward_or_reply=None):


	if not sender and frappe.session.user != "Administrator":
		sender = frappe.db.get_value("Email Config",{"name":email_account},"email_id")
	import json	
	doc = json.loads(doc)
	
	comm = frappe.get_doc({
		"doctype":"Outbox",
		"subject": subject,
		"content": content,
		"tag": doc.get('tag') or "",
		"customer": doc.get("customer") or "",
		"supplier": doc.get("supplier") or "",
		"sender": sender,
		"recipients": recipients,
	})
	comm.insert(ignore_permissions=True)

	#attachments = get_attachments(doctype,name)
	attachments = prepare_attachments(attachments)
	for attachment in attachments:
		file_data = {}
		furl = "/files/%s"%attachment["fname"] 
		file_data.update({
			"doctype": "File Data",
			"attached_to_doctype":"Outbox",
			"attached_to_name":comm.name,
			"file_url":furl,
			"file_name":attachment["fname"]
			
		})
		f = frappe.get_doc(file_data)
		f.flags.ignore_permissions = True
		f.insert();

	recipients = get_recipients(recipients)
	attachments = prepare_attachments(attachments)
	
	mailbox.sendmail(
		recipients=recipients,
		sender=sender,
		subject=subject,
		content=content,
		attachments=attachments,
	)

	doc = frappe.get_doc("Inbox",name)
	if forward_or_reply == 'reply':
		doc.tag = 'Responded'
	elif forward_or_reply == 'forward':
		doc.tag = 'Forwarded to Other User'	
	doc.save(ignore_permissions=True)

	return {
		"name": comm.name,
		"recipients": ", ".join(recipients) if recipients else None

	}