Getting Error while sending mail Via Custom Script

This is the traceback of error

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 61, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 21, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 56, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1013, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/communication/email.py", line 75, in make
    comm.insert(ignore_permissions=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 221, in insert
    self._validate_links()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 731, in _validate_links
    invalid_links, cancelled_links = self.get_invalid_links()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 471, in get_invalid_links
    values.name = doctype
AttributeError: 'NoneType' object has no attribute 'name'

The code I’m using is this:

      frappe.call({
      method: "frappe.core.doctype.communication.email.make",
      args: {
      recipients: "my_email@mail.com",
      content: b,                // this b variable contains html code
      subject: "Test",
      doctype: "Panel",          //name of doctype (is single doctype)
      name: cur_frm.doc.name,
      send_email: 1,
      communication_medium: "Email",
      },
      async: false,
      });

Any suggestion what I am doing wrong ?

This code is working when using in a normal doctype but giving the above mentioned error in is Single doctype.

If I comment the parameter name:cur_frm.doc.name, then mail is pushed to email queue but there, I’m getting this error:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 61, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 21, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 56, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1013, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 47, in send_now
    send_one(name, now=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py", line 483, in send_one
    raise e
AttributeError: 'NoneType' object has no attribute 'encode'

Any clue ??

EDIT
One more thing. If I am trying to send e-mail from here-> image
by clicking New Email, then also I’m getting this error:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 61, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 21, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 56, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1013, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/communication/email.py", line 75, in make
    comm.insert(ignore_permissions=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 221, in insert
    self._validate_links()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 731, in _validate_links
    invalid_links, cancelled_links = self.get_invalid_links()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 471, in get_invalid_links
    values.name = doctype
AttributeError: 'NoneType' object has no attribute 'name'

name parameter is required for sending e-mail and here name is not getting but same name as of doctype name that’s why that error was coming. I guess if user selects is Single, New Email button shouldn’t be visible, just a thought :thinking: