Example #1
0
def send_email_signal_handler(sender, **kwargs):
    emailto = kwargs['emailto']
    title = kwargs['title']
    content = kwargs['content']

    msg = EmailMultiAlternatives(
        title,
        content,
        from_email=settings.DEFAULT_FROM_EMAIL,
        to=emailto)
    msg.content_subtype = "html"

    from servermanager.models import EmailSendLog
    log = EmailSendLog()
    log.title = title
    log.content = content
    log.emailto = ','.join(emailto)

    try:
        result = msg.send()
        log.send_result = result > 0
    except Exception as e:
        logger.error(f"失败邮箱号: {emailto}, {e}")
        log.send_result = False
    log.save()
Example #2
0
def send_email_signal_handler(sender, **kwargs):
    emailto = kwargs['emailto']
    title = kwargs['title']
    content = kwargs['content']
    images = kwargs['images']
    msg = EmailMultiAlternatives(title,
                                 content,
                                 from_email=settings.DEFAULT_FROM_EMAIL,
                                 to=emailto)
    msg.content_subtype = "html"
    msg.mixed_subtype = 'related'

    if images is not None:
        for key, value in images.items():
            full_path = os.path.join(EMAIL_FILES, key)
            if os.path.isfile(full_path):
                img_data = open(full_path, 'rb').read()
                img = MIMEImage(img_data, value)
                img.add_header('Content-Id', key)
                img.add_header("Content-Disposition", "inline", filename=key)
                msg.attach(img)

    from servermanager.models import EmailSendLog
    log = EmailSendLog()
    log.title = title
    log.content = content
    log.emailto = ','.join(emailto)
    try:
        result = msg.send()
        log.send_result = result > 0
    except Exception as e:
        logger.error(e)
        log.send_result = False
    log.save()
Example #3
0
    def sendmsg_withlog():
        from servermanager.models import EmailSendLog
        log = EmailSendLog()
        log.title = title
        log.content = content
        log.emailto = ','.join(emailto)

        try:
            result = msg.send()
            log.send_result = result > 0
        except Exception as e:
            logger.error(e)
            log.send_result = False
        log.save()
Example #4
0
    def sendmsg_withlog():
        from servermanager.models import EmailSendLog
        log = EmailSendLog()
        log.title = title
        log.content = content
        log.emailto = ','.join(emailto)

        try:
            result = msg.send()
            log.send_result = result > 0
        except Exception as e:
            logger.error(e)
            log.send_result = False
        log.save()