def _attach_files ( filepaths , email_ ) : for filepath in filepaths : base = os . path . basename ( filepath ) with open ( filepath , "rb" ) as file : part = MIMEApplication ( file . read ( ) , Name = base ) part [ "Content-Disposition" ] = 'attachment; filename="%s"' % base email_ . attach ( part )
python send email attach multiple files
Take a list of filepaths and attach the files to a MIMEMultipart .
def _attach_files(filepaths, email_):
    """Take a list of filepaths and attach the files to a MIMEMultipart.

    Args:
        filepaths (list(str)): A list of filepaths.
        email_ (email.MIMEMultipart): A MIMEMultipart email_.
    """
    for filepath in filepaths:
        base = os.path.basename(filepath)
        with open(filepath, "rb") as file:
            part = MIMEApplication(file.read(), Name=base)
            part["Content-Disposition"] = 'attachment; filename="%s"' % base
            email_.attach(part)