是否可以添加Python代码,该代码可以访问运行它的机器上的文件&;将它们邮寄到Angular2 Web应用程序?

是否可以添加Python代码,该代码可以访问运行它的机器上的文件&;将它们邮寄到Angular2 Web应用程序?,python,angular,Python,Angular,我有一个正在运行的Angular2应用程序,目前已在Firebase上托管。 然后我有一个python(2.7)代码,用户可以使用它将一些文件(在他的计算机上本地显示)发送给某个人,这两个人都有gmail帐户 我测试了这段代码,它在我的笔记本电脑上运行良好 我的问题是,如何在现有的Angular2 Web应用程序中包含此python代码,使其与在计算机上运行的方式相同,并发送带有附件的邮件 以下是我的Python代码: # Python code to illustrate Sending ma

我有一个正在运行的Angular2应用程序,目前已在Firebase上托管。 然后我有一个python(2.7)代码,用户可以使用它将一些文件(在他的计算机上本地显示)发送给某个人,这两个人都有gmail帐户

我测试了这段代码,它在我的笔记本电脑上运行良好

我的问题是,如何在现有的Angular2 Web应用程序中包含此python代码,使其与在计算机上运行的方式相同,并发送带有附件的邮件

以下是我的Python代码:

# Python code to illustrate Sending mail with attachments
# from your Gmail account 

# libraries to be imported
import os
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders

fromaddr = "sender@gmail.com"
toaddr = "recipient@gmail.com"

# instance of MIMEMultipart
msg = MIMEMultipart()

# storing the senders email address  
msg['From'] = fromaddr

# storing the receivers email address 
msg['To'] = toaddr

# storing the subject 
msg['Subject'] = "Trial Attachments"

# string to store the body of the mail
body = "Just checking if Images would go"

# attach the body with the msg instance
msg.attach(MIMEText(body, 'plain'))

# open the file to be sent 
#filename = "tash.png"
folder = os.listdir("/path/to-some/folder/")
for f in folder:
    filename = f 
    attachment = open("/path/to-some/folder/%s" %(f), "rb")

    # instance of MIMEBase and named as p
    p = MIMEBase('application', 'octet-stream')

    # To change the payload into encoded form
    p.set_payload((attachment).read())

    # encode into base64
    encoders.encode_base64(p)

    p.add_header('Content-Disposition', "attachment; filename= %s" %    filename)

    # attach the instance 'p' to instance 'msg'
    msg.attach(p)

# creates SMTP session
s = smtplib.SMTP('smtp.gmail.com', 587)

# start TLS for security
s.starttls()

# Authentication
s.login(fromaddr, "######")

# Converts the Multipart msg into a string
text = msg.as_string()

# sending the mail
try:
    s.sendmail(fromaddr, toaddr, text)
    print "Successfully sent email"
except:
    print "Failed to send mail"

# terminating the session
s.quit()