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 }
def validated_email_addrs(recipients): recipients = get_recipients(recipients) for recipient in recipients: if not validate_email_add(recipient): return False return True