emails.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:SPF 作者: Exploit-install 项目源码 文件源码
def send_email_account(remote_server, remote_port, username, password, email_to, email_from, display_name, subject, body, attach_fname, attach_filepath, debug=False):
    if (remote_server == "smtp.gmail.com"):
        send_email_gmail(username, password, email_to, email_from, subject, body, debug)
    else:
        # 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, remote_port)

        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', "attachment; filename= %s" % attach_fname)
            msg.attach(part)

        smtp_sendmail_return = ""
        if debug:
            server.set_debuglevel(True)
        try:
            server.login(username, password)
            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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号