@cmd def run_notification(app_name=None): from erpnext.setup.doctype.site_master.site_master import send_confirmation_emails send_confirmation_emails() frappe.destroy() below function is written in site_master doctype def run_notification() import MySQLdb conn = MySQLdb.connect (host = "localhost",user = "stitch7",passwd = "iHfVPACi5GZGxjd7",db = "stitch7") from frappe.utils import get_url, cstr cur = conn.cursor() usr=[] cur.execute("select distinct(parent) from `tabUserRole` where role='HR Manager' and parent<> 'Administrator'") for row in cur.fetchall() : usr.append(row[0]) cur.close () conn.close () import frappe frappe.connect(site='demo') # as connected from to another db from mysql was giving error for send email so reconnected to default frappe site from frappe.utils.email_lib import sendmail sendmail(recipients=usr, msg='msg', subject='Not Confirmed Employees list')