def send_email_direct(email_to, email_from, display_name, subject, body, attach_fname, attach_filepath, debug=False):
    # find the appropiate mail server
    domain = email_to.split('@')[1]
    remote_server = get_mx_record(domain)
    if (remote_server is None):
        print "No valid email server could be found for [%s]!" % (email_to)
        return

    # make sure we have a display name
    if (not display_name):
        display_name = email_from

    # connect to remote mail server and forward message on 
    server = smtplib.SMTP(remote_server, 25)

    msg = MIMEMultipart()
    msg['From'] = display_name
    msg['To'] = email_to
    msg['Subject'] = subject
    msg.attach(MIMEText(body, 'plain'))

    if (attach_fname):
        attachment = open(attach_filepath, "rb")
        part = MIMEBase('application', 'octet-stream')
        part.set_payload((attachment).read())
        encoders.encode_base64(part)
        part.add_header('Content-Disposition', attach_fname % "attachment; filename= %s")
        msg.attach(part)

    smtp_sendmail_return = ""
    if debug:
        server.set_debuglevel(True)
    try:
        smtp_sendmail_return = server.sendmail(email_from, email_to, msg.as_string())
    except Exception, e:
        exception = 'SMTP Exception:\n' + str( e) + '\n' + str( smtp_sendmail_return)
    finally:
        server.quit()
dataset/ETHPy150Open tatanus/SPF/spf/core/emails.py/send_email_direct/swapped operands of `%`