Commit 1cecdc29 authored by Hamaker, Alec's avatar Hamaker, Alec
Browse files

Added support for a string a 'files' attachment arg.

parent 455489c9
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -49,6 +49,16 @@ def send_email(subject, text, files=None):
                msg.attach(part)
            else:
                logger.error(f'Failed to attach file {f}. {f} is not a file.')
    elif isistance(files, str) and len(files) > 0:
        if os.path.isfile(files):
            with open(files, 'rb') as att_file:
                part = MIMEApplication(att_file.read())
            part['Content-Disposition'] = ('attachment; filename='
                                           f'"{os.path.basename(files)}"')
            msg.attach(part)
        else:
            logger.error(f'Failed to attach file {files}. {files} is not a '
                         'file.')
    else:
        logger.error(f'Failed to attach files "{files}". Please ensure that '
                     '"files" is passed as type "list"')