app.py
def send_email(mailcfg, subject, attachments):
    """ Send email with credentials from mailcfg dict. Returns error or None
    """
    logger.debug(
        'Подготовка письма для %s с количеством вложений: %d.' % (mailcfg['TO'], len(attachments)))
    
    msg = MIMEMultipart()

    msg['From'] = mailcfg['FROM']
    msg['To'] = mailcfg['TO']
    msg['Subject'] = subject

    msg.attach(MIMEText("File uploading started at %s" % datetime.now()))


    # # send pic:
    # with open("email_practice.png", 'rb') as file:
    # 	msg.attach(MIMEImage(file.read()))
    # with smtplib.SMTP_SSL(mailcfg.SERVER, mailcfg.PORT) as smtp:
    # 	smtp.login(mailcfg.USERNAME, mailcfg.PASSWORD)
    # 	smtp.send_message(msg)
    # exit()

    # send attachments:
    for path in attachments:
        part = MIMEBase('application', "octet-stream")
        logger.debug('Начало загрузки файла по пути: %s' % path)
        try:
            with open(path, 'rb') as file:
                part.set_payload(file.read())
            logger.debug('Загружен.')
            encoders.encode_base64(part)
            logger.debug('Закодирован base64.')
        except Exception as ex:
            logger.error(type(ex).__name__ + str(ex))
        part.add_header('Content-Disposition',
                        'attachment; filename="{}"'.format(Path(path).name))
        msg.attach(part)

    logger.debug('Начало соединения с сервером %s.' % mailcfg['SERVER'])
    try:
        with smtplib.SMTP_SSL(mailcfg['SERVER'], mailcfg['PORT']) as smtp:
            smtp.login(mailcfg['USERNAME'], mailcfg['PASSWORD'])
            logger.debug('Авторизуемся как %s.' % mailcfg['USERNAME'])
            smtp.sendmail(mailcfg['FROM'], mailcfg['TO'], msg.as_string())
        logger.debug('Отправлено успешно.')
        return None
    # except SMTPSenderRefused as ex:
    except Exception as ex:
        print(type(ex).__name__ + str(ex))
        logger.error(type(ex).__name__ + str(ex))
        return ex
 Send email with credentials from mailcfg dict. Returns error or None
    
Send email with credentials from mailcfg dict. Returns error or None
Send email with credentials from mailcfg dict . Returns error or None
def send_email(mailcfg, subject, attachments):
    logger.debug(
        'Подготовка письма для %s с количеством вложений: %d.' % (mailcfg['TO'], len(attachments)))
    msg = MIMEMultipart()
    msg['From'] = mailcfg['FROM']
    msg['To'] = mailcfg['TO']
    msg['Subject'] = subject
    msg.attach(MIMEText("File uploading started at %s" % datetime.now()))
    for path in attachments:
        part = MIMEBase('application', "octet-stream")
        logger.debug('Начало загрузки файла по пути: %s' % path)
        try:
            with open(path, 'rb') as file:
                part.set_payload(file.read())
            logger.debug('Загружен.')
            encoders.encode_base64(part)
            logger.debug('Закодирован base64.')
        except Exception as ex:
            logger.error(type(ex).__name__ + str(ex))
        part.add_header('Content-Disposition',
                        'attachment; filename="{}"'.format(Path(path).name))
        msg.attach(part)
    logger.debug('Начало соединения с сервером %s.' % mailcfg['SERVER'])
    try:
        with smtplib.SMTP_SSL(mailcfg['SERVER'], mailcfg['PORT']) as smtp:
            smtp.login(mailcfg['USERNAME'], mailcfg['PASSWORD'])
            logger.debug('Авторизуемся как %s.' % mailcfg['USERNAME'])
            smtp.sendmail(mailcfg['FROM'], mailcfg['TO'], msg.as_string())
        logger.debug('Отправлено успешно.')
        return None
    except Exception as ex:
        print(type(ex).__name__ + str(ex))
        logger.error(type(ex).__name__ + str(ex))
        return ex
def send_email ( mailcfg , subject , attachments ) : logger . debug ( 'Подготовка письма для %s с количеством вложений: %d.' % (mailcfg['TO'], len(attachments))) msg = MIMEMultipart ( ) msg [ 'From' ] = mailcfg [ 'FROM' ] msg [ 'To' ] = mailcfg [ 'TO' ] msg [ 'Subject' ] = subject msg . attach ( MIMEText ( "File uploading started at %s" % datetime . now ( ) ) ) for path in attachments : part = MIMEBase ( 'application' , "octet-stream" ) logger . debug ( 'Начало загрузки файла по пути: %s' % path) try : with open ( path , 'rb' ) as file : part . set_payload ( file . read ( ) ) logger . debug ( 'Загружен.') encoders . encode_base64 ( part ) logger . debug ( 'Закодирован base64.') except Exception as ex : logger . error ( type ( ex ) . __name__ + str ( ex ) ) part . add_header ( 'Content-Disposition' , 'attachment; filename="{}"' . format ( Path ( path ) . name ) ) msg . attach ( part ) logger . debug ( 'Начало соединения с сервером %s.' % mailcfg['SERVER']) try : with smtplib . SMTP_SSL ( mailcfg [ 'SERVER' ] , mailcfg [ 'PORT' ] ) as smtp : smtp . login ( mailcfg [ 'USERNAME' ] , mailcfg [ 'PASSWORD' ] ) logger . debug ( 'Авторизуемся как %s.' % mailcfg['USE N ME']) smtp . sendmail ( mailcfg [ 'FROM' ] , mailcfg [ 'TO' ] , msg . as_string ( ) ) logger . debug ( 'Отправлено успешно.') return None except Exception as ex : print ( type ( ex ) . __name__ + str ( ex ) ) logger . error ( type ( ex ) . __name__ + str ( ex ) ) return ex
Send email with credentials from mailcfg dict.
Send email with credentials from mailcfg dict .
""" Send email with credentials from mailcfg dict. Returns error or None
    """ # # send pic: # with open("email_practice.png", 'rb') as file: # 	msg.attach(MIMEImage(file.read())) # with smtplib.SMTP_SSL(mailcfg.SERVER, mailcfg.PORT) as smtp: # 	smtp.login(mailcfg.USERNAME, mailcfg.PASSWORD) # 	smtp.send_message(msg) # exit() # send attachments: # except SMTPSenderRefused as ex:
mailcfg
subject
attachments