ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

Which arguments available to frm.email_doc?

Trying to use frm.email_doc().

Can’t find apropriate documentation for it’s abilities.
I would like to be able to use the script to perform the following:

  1. Inserting a “To:” value.
  2. Inserting text in the message section
  3. If possible remove the tick from “Attach Document Print” checkbox

You can only pass “message” as an argument frm.email_doc(message), rest of the values are picked from frm object.

1 Like

So, basically you’re saying there is no control of the “Send email” dialog box. Am I right?

I’m myself not sure how much you can control. You can check the various implementation of email_doc in frappe codebase to know more.

Well,
as mentioned, I can’t find the documentation for the frm.email_doc() dialog.
worked around it through:
location.href = GetMailtoLink();

function GetMailtoLink() {...return "mailto:" + mailToAddress + "?subject=" + varSubject + "body=" + bodyText;}

worked like charm

however, If anyone knows where to find relevant doc it would be great!

frm.email_doc is just a thin layer over the CommunicationComposer class. You can specify a few more parameters by creating a new instance of that directly:

If you want more functionality, it’s pretty straightforward to extend that class either client or server side.

Thank you.
I will check this out.

I’m not sure why, but this does not work:

function emailList(frm,toAddress,sbjct,message){
    frm.set_value('sent_bool',true);
	new frappe.views.CommunicationComposer({
		doc: frm.doc,
		frm: frm,
		subject: sbjct,
		recipients: toAddress,
		attach_document_print: true,
		message: message,
		real_name: frm.doc.real_name || frm.doc.contact_display || frm.doc.contact_name
	});
}

the status is stuck with the “sending” attribute, and does not send…
besides, I can insert the recepient email and subject but the message body does not cooperate.

:unamused:

Yeah, if you want to set the message body this way, I think you’ll have to override the make method. Right now, the function doesn’t seem to do anything to set the message body.

As for getting stuck on sending, I doubt that has anything to do with the javascript. In any case, your code works fine on my system. Are you able to send emails manually?

Maybe this will help

Thaks, but this is for a server script.
If I were to use this direction, I rather using the mailto: workaround, so the user will be able to review the mail prior to sending it.

about the sending, I can’t really explain this, because when hitting the built in New Email button works fine. It’s when I use the original frm.email_doc() or the aforementioned emailList(frm,toAddress,sbjct,message) I get stuck with the following:

and indeed as you said message is not inserted in both cases

Hmm…that’s really weird. I can’t think of any reason why instantiating the object manually would be any different. Perhaps try eliminating parameter lines one by one to see if they work? Can you check the email queue to see if there are any error messages?

Well, as mentioned, I also tried using the original method by inserting frm.email_doc('Bla bla'); to the script (it is the only line of code after right now) and got the same result…
about the email queue:

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/background_jobs.py”, line 100, in execute_job
method(**kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py”, line 419, in send_one
frappe.get_doc(‘Communication’, email.communication).set_delivery_status(commit=auto_commit)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 850, in get_doc
doc = frappe.model.document.get_doc(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 75, in get_doc
return controller(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 113, in init
self.load_from_db()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 156, in load_from_db
frappe.throw(("{0} {1} not found").format((self.doctype), self.name), frappe.DoesNotExistError)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 432, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’, is_minimizable=is_minimizable, wide=wide, as_list=as_list)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 411, in msgprint
_raise_exception()
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 365, in _raise_exception
raise raise_exception(msg)
frappe.exceptions.DoesNotExistError: Communication af0341fa54 not found

I am baffled… o_O

That’s noteworthy. The Communication doctype is the email “record”, which then gets transformed into a email queue doc on creation. I wish I had a clearer picture of what’s going on, but for some reason the communication doctype creation is failing. Anything in the browser console when you hit send?

Nope… sorry.