'Build recipients and send email alert'

def send(self, doc):

    def get_attachment(doc):
        u'    check    print    settings    are    attach    the    pdf    '
        if (not self.attach_print):
            return None
        print_settings = frappe.get_doc(u'Print    Settings', u'Print    Settings')
        if (((doc.docstatus == 0) and (not print_settings.allow_print_for_draft)) or ((doc.docstatus == 2) and (not print_settings.allow_print_for_cancelled))):
            status = (u'Draft' if (doc.docstatus == 0) else u'Cancelled')
            frappe.throw(_(u'Not    allowed    to    attach    {0}    document,\n DCTB  DCTB  DCTB  DCTB  DCTB please    enable    Allow    Print    For    {0}    in    Print    Settings'.format(status)), title=_(u'Error    in    Email    Alert'))
        else:
            return [frappe.attach_print(doc.doctype, doc.name)]
    context = get_context(doc)
    recipients = []
    for recipient in self.recipients:
        if recipient.condition:
            if (not frappe.safe_eval(recipient.condition, None, context)):
                continue
        if recipient.email_by_document_field:
            if validate_email_add(doc.get(recipient.email_by_document_field)):
                recipient.email_by_document_field = doc.get(recipient.email_by_document_field).replace(u',', u'\n')
                recipients = (recipients + recipient.email_by_document_field.split(u'\n'))
        if recipient.cc:
            recipient.cc = recipient.cc.replace(u',', u'\n')
            recipients = (recipients + recipient.cc.split(u'\n'))
        if recipient.email_by_role:
            emails = get_emails_from_role(recipient.email_by_role)
            for email in emails:
                recipients = (recipients + email.split(u'\n'))
    if (not recipients):
        return
    recipients = list(set(recipients))
    subject = self.subject
    context = {u'doc': doc, u'alert': self, u'comments': None}
    if self.is_standard:
        self.load_standard_properties(context)
    if doc.get(u'_comments'):
        context[u'comments'] = json.loads(doc.get(u'_comments'))
    if (u'{' in subject):
        subject = frappe.render_template(self.subject, context)
    attachments = get_attachment(doc)
    frappe.sendmail(recipients=recipients, subject=subject, message=frappe.render_template(self.message, context), reference_doctype=doc.doctype, reference_name=doc.name, attachments=attachments)
    if self.set_property_after_alert:
        frappe.db.set_value(doc.doctype, doc.name, self.set_property_after_alert, self.property_value, update_modified=False)
        doc.set(self.set_property_after_alert, self.property_value)
